PHP Headless Browser? [closed]

2019-01-07 19:38发布

Is there a headless browser library for PHP? Would like something that has a JS engine built into it. FOSS preferred.

7条回答
Evening l夕情丶
2楼-- · 2019-01-07 19:56

Check out mink and it's support for zombie as a back-end.

It looks quite good, and appears to be well supported.


Edit:

Unfortunately, php has no native javascript interpreter; so if you are looking for a pure php implementation including javascript support, currently, you will not find it. For headless with javascript support, you will have to rely on something like node.js or phantomjs on the back-end.

I'm sure you've seen them already, but for other options that are either headed or lack javascript support, Mink's other backends are worth perusing.

查看更多
【Aperson】
3楼-- · 2019-01-07 19:58

Well, someone could create a bastard headless web browser running in PHP, complete with Javascript support implemented in PHP!

查看更多
Emotional °昔
4楼-- · 2019-01-07 20:03

PhantomJS - http://phantomjs.org/

PhantomJS is a headless WebKit with JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.

You can couple it with something like php-PhantomjsRunner (now deprecated) if you want or bake your own.

When setup and ready to start testing with PhantomJS, pick out one of the various Testing Frameworks at your disposal.

I recently also came across this tutorial from tutsplus should it help anyone.

查看更多
Deceive 欺骗
5楼-- · 2019-01-07 20:05

Use the HTMLUnit driver, which is part of the Selenium project. WebDriver is based on Webkit (I believe) and so using HTMLUnit (from Selenium) basically is the Java solution. Then, I believe you can call Java code from PHP, although I am unsure on what the details are of getting that working.

查看更多
神经病院院长
6楼-- · 2019-01-07 20:12

Goutte is a simple headless browser for PHP. https://github.com/fabpot/Goutte

Unfortunately it doesn't support JS.

查看更多
放我归山
7楼-- · 2019-01-07 20:12

If you're not limited to PHP, or you're able to use system calls, check out xvfb, it's a virtual frame buffer, and you can use that to run Linux based browsers (firefox) with complete JS functionality. You can even pull in the screen data too, and write it to a file.

I've done this before when gathering specific metrics.

查看更多
登录 后发表回答