Pyphantomjs 导致 python 崩溃

发布于 2024-11-24 17:51:36 字数 475 浏览 1 评论 0原文

我只是想用 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()

My crash report.

I'm running python 2.7 on Snow Leopard.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍景流年 2024-12-01 17:51:36

您是否在 Google 上搜索过“PhantomJS API 参考”或“PyPhantomJS API 参考”?作为第一个链接,这两个搜索词都会产生良好的结果。我不知道你怎么能说文档很糟糕,因为如果你只是查找它,它就到处都是。

如果您阅读过项目描述1,您就会知道它是使用 JS 编写的脚本,而不是Python(虽然理论上可行,但做起来有点困难,我以前没有尝试过)。该程序在下载时附带了一个示例目录,你怎么会错过呢?查看示例(可以从下载页面下载,并且还随zip 文件下载!)了解如何使用该程序。

您可以在 PyPhantomJS API 参考中找到更多信息。

项目页面:PhantomJS | PyPhantomJS

适合您的示例脚本:

var page = new WebPage();
page.open('http://www.google.com/', function(status) {
    // do something
    phantom.exit();
});

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:

var page = new WebPage();
page.open('http://www.google.com/', function(status) {
    // do something
    phantom.exit();
});

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文