下面来演示QueryList使用PhantomJS插件抓取JS动态创建的页面内容。
安装
使用Composer安装:
安装QueryList
composer require jaeger/querylist GitHub: https://github测试数据/jae-jae/QueryList
安装PhantomJS插件
composer require jaeger/querylist-phantomjs GitHub: https://github测试数据/jae-jae/QueryList-PhantomJS
自定义一个复杂的请求:
$data = $ql->browser(function (\JonnyW\PhantomJs\Http\RequestInterface $r){$r->setMethod('GET');$r->setUrl('https://m.toutiao测试数据');$r->setTimeout(10000); // 10 seconds$r->setDelay(3); // 3 secondsreturn $r;})->find('p')->texts();print_r($data->all());
开启debug模式,并从本地加载cookie文件:
$data = $ql->browser(function (\JonnyW\PhantomJs\Http\RequestInterface $r){$r->setMethod('GET');$r->setUrl('https://m.toutiao测试数据');$r->setTimeout(10000); // 10 seconds$r->setDelay(3); // 3 secondsreturn $r;},true,['--cookies-file' => '/path/to/cookies.txt'])->rules(['title' => ['p','text'],'link' => ['a','href']])->query()->getData();print_r($data->all());
查看更多关于php使用QueryList入门之轻松采集JavaScript动态渲染页面的详细内容...