1

Scraping next pages issue with selenium

is somewhat similar althogh i dont want to make it more complicated by using with bs4

I want to scrape all 10 titles (links to pdfs) on every page. Here is the code that throws a StaleElementReferenceException: Message: stale element reference: element is not attached to the page document (at i.click())

driver.find_element_by_css_selector('button[class="btn btn-primary"][type="submit"]').click()    
    
for j in range(10):
    pdfs = driver.find_elements_by_css_selector(".title a")
    if j < 10:
        nextpg = driver.find_element_by_css_selector(".tx-pagebrowse-page button")
        pdfs = driver.find_elements_by_css_selector(".title a")
    for i in pdfs:
        i.click()
        time.sleep(5)
    if j < 10:
        nextpg.click()
    else:
        break

below it shows that the first page is a type=list list with the right titles

pdfs = driver.find_elements_by_css_selector(".title a")
print(type(pdfs))
for my_pdf in pdfs:
    print(my_pdf.get_attribute('innerHTML'))

<class 'list'>
                                dfhgadr asfdgsd
                                sDF SDF 
                                SDFSDF sdf
                                SDF DSfdf
                                SDFD sdf
                                SDFSdf fdf
                                zewr4
                                sHSDFG 
                                RSZJRT
                                dhff fgf

1 Answer 1

0

Instead of pdfs[[i]].click() You may try as follows:

 i.click()
Sign up to request clarification or add additional context in comments.

10 Comments

Hi. ´AttributeError: 'int' object has no attribute 'click'´
Try to use as: str(i).click()
AttributeError: 'str' object has no attribute 'click'
Instead of clic() , try to use Send_keys(Keys.ENTER)
Because element may remove from DOM.Please take help fron here:stackoverflow.com/questions/18225997/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.