Pyphantomjs 导致 python 崩溃
我只是想用 pyphantomjs 打开网页,但它使 python碰撞。我不知道是否存在问题或者我是否使用错误,因为该文档是我见过的最糟糕的文档之一......
我的代码:
from pyphantomjs import webpage
if __name__ == '__main__':
wp = webpage.WebPage()
wp.open("www.google.com")
print wp.content()
我在 Snow Leopard 上运行 python 2.7。
I'm just trying to open a web page with pyphantomjs, but it makes python crash. I don't know if there is a problem or if I am just using it wrong, as the documentation is one of the crappiest I've seen...
My code:
from pyphantomjs import webpage
if __name__ == '__main__':
wp = webpage.WebPage()
wp.open("www.google.com")
print wp.content()
I'm running python 2.7 on Snow Leopard.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在 Google 上搜索过“PhantomJS API 参考”或“PyPhantomJS API 参考”?作为第一个链接,这两个搜索词都会产生良好的结果。我不知道你怎么能说文档很糟糕,因为如果你只是查找它,它就到处都是。
如果您阅读过项目描述1,您就会知道它是使用 JS 编写的脚本,而不是Python(虽然理论上可行,但做起来有点困难,我以前没有尝试过)。该程序在下载时附带了一个示例目录,你怎么会错过呢?查看示例(可以从下载页面下载,并且还随zip 文件下载!)了解如何使用该程序。
您可以在 PyPhantomJS API 参考中找到更多信息。
项目页面:PhantomJS | PyPhantomJS
适合您的示例脚本:
1 PyPhantomJS 是一个简约、无头、基于 WebKit、JavaScript 驱动的工具...
python pyphantomjs.py [options] script.[js|coffee] [script argument [script argument ...]]
脚本代码将像在空页面的 Web 浏览器中运行一样执行。由于 PyPhantomJS 是无头的,因此屏幕上不会显示任何可见内容。
该脚本可以是JavaScript 或CoffeeScript。
Did you do a Google search for "PhantomJS API reference" or "PyPhantomJS API reference"? Both search terms yield good results as the first link. I don't know how you can say the documentation is bad, as it's all over the place if you simply look for it.
If you had read the project description1, you would know that it's scripted using JS, not Python (while theoretically possible, it's a little hard to do, and I haven't tried before). The program comes with an examples directory when you download it, how could you have missed that? Check the examples (can be downloaded from the downloads page, and also provided with the zip file download!) on how to use the program.
You can find more information in the PyPhantomJS API Reference.
Project Pages: PhantomJS | PyPhantomJS
An example script for you:
1 PyPhantomJS is a minimalistic, headless, WebKit-based, JavaScript-driven tool...
python pyphantomjs.py [options] script.[js|coffee] [script argument [script argument ...]]
The script code will be executed as if it is running in a web browser with an empty page. Since PyPhantomJS is headless, there will not be anything visible shown up on the screen.
The script may be a JavaScript or CoffeeScript.