File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 11# coding:utf-8
22from selenium import webdriver
33from selenium .common .exceptions import ElementNotVisibleException
4+ from selenium .common .exceptions import NoSuchElementException
45from time import sleep
56import codecs
67from datetime import datetime
4647 q_and_a = []
4748 for qa in qa_elements :
4849 try :
49- q_and_a .append ((qa .find_element_by_class_name ("streamItem_header" ).find_element_by_tag_name ('h2' ).text ,
50- qa .find_element_by_class_name ("streamItem_content" ).text ))
51- except ElementNotVisibleException as e :
52- print ("ElementNotVisible: Skip QA: {}" .format (e ))
50+ q = qa .find_element_by_class_name ("streamItem_header" ).find_element_by_tag_name ('h2' ).text
51+ except (ElementNotVisibleException , NoSuchElementException ) as e :
52+ print ("ElementNotVisible: {}" .format (e ))
5353 continue
54+ try :
55+ a = qa .find_element_by_class_name ("streamItem_content" ).text
56+ except (ElementNotVisibleException , NoSuchElementException ) as e :
57+ try :
58+ print ("Check Answer card..." )
59+ a = qa .find_element_by_class_name ("asnwerCard_text" ).text
60+ except (ElementNotVisibleException , NoSuchElementException ) as e :
61+ print ("ElementNotVisible: {}" .format (e ))
62+ continue
63+ q_and_a .append ((q , a ))
5464
5565 with codecs .open ("data/askfm_data/" + face + ".txt" , "w" , "utf-8" ) as f :
5666 for q , a in q_and_a :
You can’t perform that action at this time.
0 commit comments