2

Ghost is giving me this error when I execute fallowing code:

    from ghost import Ghost
    from bs4 import BeautifulSoup

    url = "https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx"
    ghost = Ghost()

    page, resources = ghost.open(url)
    page, resources = ghost.evaluate(
         "document.getElementById('btnNowaCaptcha').click();")
    soup = BeautifulSoup(ghost.content)
    capcha = soup.find(id='imgCaptch')

But when I use pdb and execute once more last two lines everything is fine. Is anyone know why?

1 Answers1

3

I guess the page did not load fully yet, thus document.getElementById('btnNowaCaptcha') would return null; you should add

ghost.wait_for_page_loaded()  # and/or
ghost.wait_for_selector("#btnNowaCaptcha")

before the ghost.evaluate to make sure that the page is fully loaded.