Re:Phantompy - Headless WebKit engine for Python, like phant...
by fauigerzigerk on Tuesday May 21, 2013 @07:36AM
(#5742973)
I wonder if Phantompy is truly headless so it works on servers without GUI libraries and without xvfb.
QtWebKit needs access to some GUI features out of the box, but phantomjs includes platform abstraction code that avoids the dependency on an X server. That's the feature that made me migrate my own C++ crawler code to phantomjs.
Re:Phantompy - Headless WebKit engine for Python, like phant...
by kanzure on Tuesday May 21, 2013 @12:56PM
(#5744968)
Actually, you don't even need xvfb these days (and I have no idea why anyone is telling people that they do). You could use something like xserver-xorg-video-dummy. Of course, as you have pointed out, PhantomJS doesn't require an X server (as opposed to these other projects, wtf) so that it is "really really truly headless".
Re:Phantompy - Headless WebKit engine for Python, like phant...
by randallu on Tuesday May 21, 2013 @02:18PM
(#5745601)
CMake is pretty horrifically inefficient at compiling WebKit. The makefiles it generates fork to call CMake (to do things like printf in color) far more than they fork to call the compiler. The ninja generator is better, but it has various issues with long command lines on WebKit currently (trunk CMake fixes some of these, but then it doesn't make some directories in the output directory).
Also, the CMakeLists syntax is pretty nasty IMO, but it feels like gyp, cmake and autotools are in some kind of syntax ugliness competition... (Maybe because nobody ever wants to work on a build system, so they'll just do this one little hack which inevitably grows tentacles).
Re:Phantompy - Headless WebKit engine for Python, like phant...
by boothead on Tuesday May 21, 2013 @04:54AM
(#5742526)
Is there anything wrong with the python bindings to phantom? I used phantomjs (it's great)a few years ago and I thought there were some python bindings to the original phantom C++ library - could be wrong though.
Re:Phantompy - Headless WebKit engine for Python, like phant...
by Herald_MJ on Tuesday May 21, 2013 @05:44AM
(#5742673)
There were a set of Python bindings for phantom.js named PyPhantomjs, and it was included in actual phantom releases, but the maintainer moved away from the project, no-one stepped forward and it was ultimately removed from the project (https://github.com/ariya/phantomjs/issues/10344).
Re:Phantompy - Headless WebKit engine for Python, like phant...
by waitwhatwhoa on Tuesday May 21, 2013 @05:20AM
(#5742605)
Ariya Hidayat & co have put a monumental amount of effort into exposing the inner workings of webkit in phantomjs - I'm not sure I see the necessity for a python rewrite. Taking a quick look at the code, most everything I use phantomjs for outside of screenshotting is not available. A great start for sure, but unless there are some fundamental shortcomings with phantomjs that I'm unaware of, I agree with boothead that python bindings are probably the way to go.
Re:Phantompy - Headless WebKit engine for Python, like phant...
by heydenberk on Tuesday May 21, 2013 @06:36AM
(#5742804)
One thing that jumps out at me is that phantompy uses Qt5 internally, while phantomjs uses Qt4. There are lots of new WebKit features and optimizations in Qt5.
Re:Phantompy - Headless WebKit engine for Python, like phant...
by killahpriest on Tuesday May 21, 2013 @08:21AM
(#5743108)
Ghost.py seems promising but is painful to work with. Installing the dependencies took about an hour (compiling PyQt itself took about 25 minutes). When we did finally get it working, PyQt would crash after the third or fourth scrape and would take between 15 to 30 seconds per scrape. Where we used it: https://github.com/createch/PriceChecker.py/blob/master/pych....
My advice to anybody looking to do headless webkit in Python: Don't use Ghost. Try out PhantomPy and try using the Selenium webdriver for Phantom.
Re:Phantompy - Headless WebKit engine for Python, like phant...
by arikfr on Tuesday May 21, 2013 @10:28AM
(#5743820)
Just to give another perspective: I'm not sure on which OS you had those issues, but I'm successfully using Ghost.py on Ubuntu and OS/X. On OS/X it was harder to install PyQT and sometimes there were weird issues, but on Ubuntu it all went smooth.
By now I've ran it on thousands of different websites with little issues. It's true that I'm "recycling" the processes after ~10 sites, but that's mainly because of memory leaks.
EDIT: and to clarify on Ubuntu installing either PyQT or PySide (Ghost.py now supports both) was as easy as apt-get install...
Re:Phantompy - Headless WebKit engine for Python, like phant...
by killahpriest on Tuesday May 21, 2013 @10:39AM
(#5743897)
I tried (but failed to) get it to run at all on OS X. We were able to get it to run on Ubuntu, but thats where it crashed after every three to four scrapes.
Re:Phantompy - Headless WebKit engine for Python, like phant...
by encoderer on Tuesday May 21, 2013 @01:29PM
(#5745217)
There are so many half-baked headless browser projects, many building in some way on PyQT. I've made heavy use of Spynner and Ghost. Spynner especially. It always seemed to offer exactly what I needed but the inconsistent docs and endlessly-deep stack always seemed to leave successful implementation just beyond my grasp.
Now, as an OSS maintainer myself, I sympathize. But I'd love it if this or another one of these projects started breaking away from the pack and could build some critical mass. I'm all for democratization but in this case I'd gladly trade 10 mostly working projects for a single solution ran by an iron-fisted BDFL if it meant decent docs and a mostly stable API.
Re:Phantompy - Headless WebKit engine for Python, like phant...
by _seininn on Tuesday May 21, 2013 @07:31AM
(#5742954)
I've been working on a project like this that's nearing completion (it works, and the api is mostly complete). It differs from this in that it uses any normal browser to fulfill requests (via extensions).
The idea is to have a pythonic API to any browser that has reasonable support for extensions; i.e. a cross-browser scripting.
Re:Phantompy - Headless WebKit engine for Python, like phant...
by laurencerowe on Tuesday May 21, 2013 @02:33PM
(#5745751)
What does it offer over Selenium Webdriver? Yeah, the API is not terribly pythonic, but it's battle tested and stable, works across almost all browsers and there's always wrappers like Splinter (http://splinter.cobrateam.info/) if you prefer a more pythonic interface.
Re:Phantompy - Headless WebKit engine for Python, like phant...
by meerita on Tuesday May 21, 2013 @05:08AM
(#5742570)
We use it to generate images from a website. We do a product with HTML5/CSS3 and webfonts, layout it all then "screenshooting it" to make a final image with the proportions we want. It's cool because its server side and we can generate endless images based on what the user want.
Addendum: If you want to use webfonts, specially from Google, you need to recompile Phantom to support WOFF.
Re:Phantompy - Headless WebKit engine for Python, like phant...
by meerita on Tuesday May 21, 2013 @06:10AM
(#5742749)
It is not fast as we wished. The whole request and image deliver is about 2 seconds or more, It's because we're using right now the same server for everything but for what are you asking, I think is not good idea. Achieve 30fps i see it hard.
Re:Phantompy - Headless WebKit engine for Python, like phant...
by meerita on Tuesday May 21, 2013 @12:47PM
(#5744899)
To do PDF, you better install HTML->PDF command line tool than that. What this do is simply load a webkit browser and we just perform an screen of that.
Re:Phantompy - Headless WebKit engine for Python, like phant...
by DenisM on Tuesday May 21, 2013 @02:25PM
(#5745672)
Printing works differently in different engines, so I want the designer to use her HTML / chrome skills to design templates, and then render the PDF with users data using the same engine. Command line HTML to PDF tool will work too, but it will require the designer to relearn engine quirks.
Re:Phantompy - Headless WebKit engine for Python, like phant...
by yashodhan on Tuesday May 21, 2013 @05:15AM
(#5742588)
I use phantomjs to login to my bank's website and grab my balance for me.
Unfortunately my bank decided to outsource their web operation to the cheapest bidder from India and as a result their web application is beyond shit. It requires javascript to work, and therefore I needed a headless broswer engine to scrape it.
Re:Phantompy - Headless WebKit engine for Python, like phant...
by justincormack on Tuesday May 21, 2013 @09:24AM
(#5743443)
All the banks I have used in the last 10 years have required hardware tokens. Recommend you change banks even if that makes screen scraping your balance impossible....
Re:Phantompy - Headless WebKit engine for Python, like phant...
by saryant on Tuesday May 21, 2013 @02:08PM
(#5745509)
I recently built a service using PhantomJS for a client. They have graphs and charts generated with d3.js that they wanted to add to their user-specific update emails.
I built a backend service using Akka[1] and PhantomJS which would grab the appropriate user's page, render it to HTML, splice up the images and save everything to temp files. Then I had a Java process that read those back in then format and sent an email to the user.
Re:Phantompy - Headless WebKit engine for Python, like phant...
by tlarkworthy on Tuesday May 21, 2013 @07:27AM
(#5742949)
angularjs and other JS rendering techniques make the plain HTML look a mess. Google will not be able to present the page or get its content properly, so you use something like this to take snapshots of your website post rendering and expose it for indexing & website previews. (https://developers.google.com/webmasters/ajax-crawling/docs/...)
QtWebKit needs access to some GUI features out of the box, but phantomjs includes platform abstraction code that avoids the dependency on an X server. That's the feature that made me migrate my own C++ crawler code to phantomjs.
Thank you cmake, you've made working in the C ecosystem fun again.
Also, the CMakeLists syntax is pretty nasty IMO, but it feels like gyp, cmake and autotools are in some kind of syntax ugliness competition... (Maybe because nobody ever wants to work on a build system, so they'll just do this one little hack which inevitably grows tentacles).
https://code.google.com/p/gyp/wiki/GypVsCMake
https://github.com/martine/ninja
So this project is really useful.
Here's the source code, if you are interested:
https://github.com/kanzure/pyphantomjs
My advice to anybody looking to do headless webkit in Python: Don't use Ghost. Try out PhantomPy and try using the Selenium webdriver for Phantom.
We switched over the Selenium webdriver for PhantomJS and found it to be much more stable and fast. See this SO answer by another Ghost.py user who gave up: http://stackoverflow.com/a/15699761/854025. Where we used the Selenium driver: https://github.com/createch/PriceChecker.py/blob/phantom/pyc....
By now I've ran it on thousands of different websites with little issues. It's true that I'm "recycling" the processes after ~10 sites, but that's mainly because of memory leaks.
EDIT: and to clarify on Ubuntu installing either PyQT or PySide (Ghost.py now supports both) was as easy as apt-get install...
Now, as an OSS maintainer myself, I sympathize. But I'd love it if this or another one of these projects started breaking away from the pack and could build some critical mass. I'm all for democratization but in this case I'd gladly trade 10 mostly working projects for a single solution ran by an iron-fisted BDFL if it meant decent docs and a mostly stable API.
The idea is to have a pythonic API to any browser that has reasonable support for extensions; i.e. a cross-browser scripting.
Addendum: If you want to use webfonts, specially from Google, you need to recompile Phantom to support WOFF.
Unfortunately my bank decided to outsource their web operation to the cheapest bidder from India and as a result their web application is beyond shit. It requires javascript to work, and therefore I needed a headless broswer engine to scrape it.
My UK account uses 2 factor but, none of the financial sites I use in the US (4 different companies) have it.
I built a backend service using Akka[1] and PhantomJS which would grab the appropriate user's page, render it to HTML, splice up the images and save everything to temp files. Then I had a Java process that read those back in then format and sent an email to the user.
[1]: http://akka.io
[1] http://searchengineland.com/google-can-now-execute-ajax-java... [2] http://www.seomoz.org/ugc/can-google-really-access-content-i...
I see a 'cssselect' in tests.py, but I wonder how much of the DOM Api is actually supported?