首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在PHP中执行PhantomJS

如何在PHP中执行PhantomJS
EN

Stack Overflow用户
提问于 2013-11-26 04:16:27
回答 1查看 42.9K关注 0票数 19

我想在本地主机上执行PHP中的PhantomJS。

谁能解释一下如何在PHP中执行PhantomJS,以及我应该从phantomjs.org下载什么包?

EN

回答 1

Stack Overflow用户

发布于 2016-06-12 01:56:13

我最近发布了一个项目,允许PHP访问浏览器。在这里获取:https://github.com/merlinthemagic/MTS。在幕后,它依赖于PhantomJS。

下载并设置后,您只需使用以下代码:

代码语言:javascript
复制
$myUrl          = "http://www.example.com";
$windowObj      = \MTS\Factories::getDevices()->getLocalHost()->getBrowser('phantomjs')->getNewWindow($myUrl);

//now you can either retrive the DOM and parse it, like this:
$domData    = $windowObj->getDom();

//or take screen shots
$imageData    = $windowObj->screenshot();

//or use the mouse to click buttons:
$windowObj->mouseEventOnElement("[id=searchInput]", 'leftclick');

//or type with the keyboard :
$windowObj->sendKeyPresses("my search words");

//or load and execute custom javascript, fill forms etc, etc.
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20202407

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档