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
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()
Hi actually the link and the date are separate elements, like: today news 1/21/2020
Can you post a sample of the web elements you need to grab.
Did you translate the page in options.
Thank you so much Arundeep! It worked! And what if I just want to click some links contain some words?
There’s about 20 links per page, using a for loop you can driver.find_elements_by_xpath(“”)[index] for the element to click and then check it’s .text value and exit.
Hi thanks! but I want a bucket of words, like {“”,””,”‘,…},would you mind helping with my new question post, I explain the question in details. Thank you!