Solution 1 :

You can do the following to get all href tags with the text of [01-20] to open and go back.

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:
    if(len(hrefs)< 20):
        #next_page = driver.find_element_by_xpath("//font[text()='Next page']/ancestor::a")
        next_page = driver.find_element_by_link_text("下一页")
        print('No more pages')

Problem :

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:
        next_page = driver.find_element_by_link_text('')
     elif date != '[01-20]': 


Comment posted by Joyce

Hi actually the link and the date are separate elements, like: today news 1/21/2020

Comment posted by Arundeep Chohan

Can you post a sample of the web elements you need to grab.

Comment posted by Arundeep Chohan

Did you translate the page in options.

Comment posted by Joyce

no , just the original page

Comment posted by Joyce

Thank you so much Arundeep! It worked! And what if I just want to click some links contain some words?

Comment posted by Arundeep Chohan

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.

Comment posted by Joyce

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!