I am trying to click all links (and get elements) in a specific date (like today), else quit if it is published (like yesterday).
I use if-elif to achieve it but the website just continue clicking links despite of date, please find my codes here:
Any help will be highly appreciated!
dates = [date.get_attribute('innerHTML') for date in driver.find_elements_by_xpath('')]
for date in dates:
if date == '[01-20]':
links = [link.get_attribute('href') for link in driver.find_elements_by_xpath('')]
for link in links:
driver.get(link)
next_page = driver.find_element_by_link_text('')
next_page.click()
elif date != '[01-20]':
driver.close()
You can do the following to get all href tags with the text of [01-20] to open and go back.
driver.get('http://www.csisc.cn/zbscbzw/isinbm/index_list_code.shtml')
while True:
hrefs=[link.get_attribute('href') for link in driver.find_elements_by_xpath("//td[text()='[01-20]']/preceding::td[1]/a")]
for href in hrefs:
driver.get(href)
driver.back()
if(len(hrefs)< 20):
break
try:
#next_page = driver.find_element_by_xpath("//font[text()='Next page']/ancestor::a")
next_page = driver.find_element_by_link_text("下一页")
next_page.click()
except:
print('No more pages')
break
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.