我正在尝试使用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时做错了什么?