HTML Extraction with Python -


the issue being tackled being unable click , go next page on html page. html page being accessed displays results after search query. @ bottom of page, there line of numbers select page of query i.e. "1 2 3 4 next" - clicking "2" shows results on second page. if on different page number i.e. 2 or 3, line @ bottom looks like: "previous 1 2 3 4 next". using python , webdriver click next page scroll through results. first time press it, takes me next page. second time click it takes me previous page. meaning stuck on first 2 pages , cannot see results 3 , 4. noticed reason happening because of li class="arrow" tag being present twice in html code. when second call made, first tag appears 1 "arrow" class. how go clicking this?

html notes: - "li" tag defines list item

html code:

before clicking next:

<div class="list"> <ul class="line"> <li class="current page"><a href>1</a></li> <li><a href="/search_text=&&page=1">2</a></li> <li><a href="/search_text=&&page=2">3</a></li> <li><a href="/search_text=&&page=3">4</a></li> <li class="arrow"><a href="/search_text=&&page=1">next</a></li> </ul> </div> 

after clicking "next" html code looks this:

<div class="list"> <ul class="line"> <li class="arrow"><a href="/search_text=&">previous</a></li> <li><a href="/search_text=&">1</a></li> <li class="current page"><a href>2</a></li> <li><a href="/search_text=&&page=2">3</a></li> <li><a href="/search_text=&&page=3">4</a></li> <li class="arrow"><a href="/search_text=&&page=2">next</a></li> </ul> </div> 

python code:

chromedriver = "c:\temp\chromedriver.exe" os.environ["webdriver.chrome.driver"] = chromedriver driver = webdriver.chrome(executable_path=r"c:\temp\chromedriver.exe") driver.implicitly_wait(3) driver.get(urllink)   driver.find_element_by_css_selector("li.arrow").click() #takes me next page driver.find_element_by_css_selector("li.arrow").click() #takes me previous page 

..

you can use method driver.find_element_by_link_text('next') find element and, then, call .click()