php PHP无头浏览器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6578132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Headless Browser?
提问by StackOverflowNewbie
回答by Anthony Hatzopoulos
PhantomJS - http://phantomjs.org/
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.
PhantomJS 是一个带有 JavaScript API 的无头 WebKit。它对各种 Web 标准提供快速和原生支持:DOM 处理、CSS 选择器、JSON、Canvas 和 SVG。
You can couple it with something like php-PhantomjsRunner(now deprecated)if you want or bake your own.
如果您愿意,您可以将它与诸如php-PhantomjsRunner(现已弃用)之类的东西结合使用或烘焙自己的.
When setup and ready to start testing with PhantomJS, pick out one of the various Testing Frameworksat your disposal.
当设置好并准备好开始使用 PhantomJS 进行测试时,请选择您可以使用的各种测试框架之一。
I recently also came across this tutorial from tutsplusshould it help anyone.
我最近也从 tutsplus看到了这个教程,如果它对任何人有帮助的话。
回答by David
Check out minkand it's support for zombieas 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 purephp 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.
不幸的是,php 没有原生的 javascript 解释器;因此,如果您正在寻找包括 javascript 支持的纯php 实现,目前,您将找不到它。对于具有 javascript 支持的无头,您将不得不依赖后端的 node.js 或 phantomjs 之类的东西。
I'm sure you've seen them already, but for other options that are either headed or lack javascript support, Mink's other backendsare worth perusing.
我相信你已经看过它们了,但是对于其他有头或缺乏 javascript 支持的选项,Mink 的其他后端值得细读。
回答by Xeoncross
You sound like you need http://seleniumhq.org/which can also be used with PHPUnitto run unit tests.
您听起来像需要http://seleniumhq.org/,它也可以与PHPUnit一起使用来运行单元测试。
Also take a look at SimpleTest Browser.
另请查看SimpleTest Browser。
回答by Michal Trojanowski
Goutte is a simple headless browser for PHP. https://github.com/fabpot/Goutte
Goutte 是一个简单的 PHP 无头浏览器。https://github.com/fabpot/Goutte
Unfortunately it doesn't support JS.
不幸的是它不支持JS。
回答by Prof. Falken contract breached
Well, someone couldcreate a bastard headless web browser running in PHP, complete with Javascript support implemented in PHP!
好吧,有人可以创建一个在 PHP 中运行的混蛋无头 Web 浏览器,并在 PHP 中实现了Javascript 支持!
回答by djangofan
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.
使用HTMLUnit 驱动程序,它是 Selenium 项目的一部分。WebDriver 基于 Webkit(我相信),因此使用 HTMLUnit(来自 Selenium)基本上是 Java 解决方案。然后,我相信您可以从 PHP 调用 Java 代码,尽管我不确定让该代码工作的细节是什么。
回答by Tango Bravo
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.
如果您不限于 PHP,或者您能够使用系统调用,请查看 xvfb,它是一个虚拟帧缓冲区,您可以使用它来运行具有完整 JS 功能的基于 Linux 的浏览器 (firefox)。您甚至可以拉入屏幕数据,并将其写入文件。
I've done this before when gathering specific metrics.
我之前在收集特定指标时已经这样做了。