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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With