第一次执行cod时“TypeError:'null'不是对象”

2024-06-07 23:05:01 发布

您现在位置:Python中文网/ 问答频道 /正文

当我执行以下代码时,Ghost给了我这个错误:

    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')

但当我使用pdb再次执行最后两行时,一切都很好。 有人知道为什么吗?在


Tags: 代码fromhttpsimporturl错误pagestat
1条回答
网友
1楼 · 发布于 2024-06-07 23:05:01

我猜页面还没有完全加载,因此document.getElementById('btnNowaCaptcha')将返回{};您应该添加

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

以确保页面已完全加载。在

相关问题 更多 >

    热门问题