我正在尝试使用 Ghost.py 进行一些网络抓取。我正在尝试关注一个链接,但 Ghost 似乎并未真正评估 javascript 并关注该链接。我的问题是我在一个 HTTPS 会话中并且不能使用重定向。我还查看了其他选项(如 selenium),但我无法在将运行脚本的机器上安装浏览器。我还有一些 javascript 评估,所以我不能使用 mechanize。
这就是我要做的...
## Open the website
page,resources = ghost.open('https://my.url.com/')
## Fill textboxes of the form (the form didn't have a name)
result, resources = ghost.set_field_value("input[name=UserName]", "myUser")
result, resources = ghost.set_field_value("input[name=Password]", "myPass")
## Submitting the form
result, resources = ghost.evaluate( "document.getElementsByClassName('loginform')[0].submit();", expect_loading=True)
## Print the link to make sure that's the one I want to follow
#result, resources = ghost.evaluate( "document.links[4].href")
## Click the link
result, resources = ghost.evaluate( "document.links[4].click()")
#print ghost.content
当我查看 ghost.content 时,我仍在同一页面上,结果为空。我注意到,当我在尝试评估点击时添加 expect_loading=True 时,出现超时错误。
当我尝试在 Chrome 开发者工具控制台中运行 javascript 时,我得到
event.returnValue 已弃用。请改用标准 event.preventDefault()。
但是该页面确实正确加载了链接的网址。
欢迎任何想法。
查尔斯