2

我正在尝试使用 python 的 ghost 库在无头浏览器中单击一个元素,如下所示:

ghost = Ghost()
USERAGENT = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"

with ghost.start():
    session = Session(ghost, download_images=True, display=True, user_agent=USERAGENT)
    session.load_cookies("cookies.txt", keep_old=False)
    page, rs = session.open("{url-here}", timeout=120)
    session.wait_for_page_loaded(timeout=None)
    assert page.http_status == 200

    while session.exists("#selector"):
        page, rs = ghost.click("#selector")
        session.wait_for_page_loaded(timeout=None)

这将返回错误消息:

AttributeError: 'Ghost' object has no attribute 'click'

我也试过:

page, rs = ghost.evaluate("document.getElementByClassName('#selector').click();", expect_loading=True)

这给出了相同的错误消息。我在使用 Ghost 时做错了什么?

4

0 回答 0