|-摘 PHP Querylist采集插件Puppeteer的安装
此方法已经不好用了 2023年12月备注
使用PuppeteerDOM解析JavaScript动态渲染的页面。使用此插件需要有一定的Node.js基础知识,并且会配置Node运行环境。
此插件是基于PuPHPeteer包的简单封装,支持使用Puppeteer所有的API,非常强大!
环境要求
PHP >= 7.1
Node >= 8
安装
1, 安装插件
composer require jaeger/querylist-puppeteer --ignore-platform-reqs
2,安装Node依赖(与composer一样在项目根目录下执行)
如果不是在项目根目录执行,之后运行QueryList代码会报错,提示 Cannot find module 'lodash' Require stack,但是你安装了lodash,还是一样会报这个错,所以npm或者yarn安装时要在项目根目录
Error:The command "'node' '/.../vendor/nesk/rialto/src/node-process/serve.js' '/.../vendor/nesk/puphpeteer/src/PuppeteerConnectionDelegate.js' '{"idle_timeout":60,"log_node_console":false,"log_browser_console":false}'" failed. Exit Code: 1(General error) Working directory: /.../frontend/web Output: ================ Error Output: ================ node:internal/modules/cjs/loader:936 throw err; ^ Error: Cannot find module 'lodash' Require stack: - /.../vendor/nesk/rialto/src/node-process/NodeInterceptors/StandardStreamsInterceptor.js - /.../vendor/nesk/rialto/src/node-process/NodeInterceptors/ConsoleInterceptor.js - /.../vendor/nesk/rialto/src/node-process/serve.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15) at Function.Module._load (node:internal/modules/cjs/loader:778:27) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at Object. (/.../vendor/nesk/rialto/src/node-process/NodeInterceptors/StandardStreamsInterceptor.js:3:11) at Module._compile (node:internal/modules/cjs/loader:1105:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19) { code: 'MODULE_NOT_FOUND', requireStack: [ '/.../vendor/nesk/rialto/src/node-process/NodeInterceptors/StandardStreamsInterceptor.js', '/.../vendor/nesk/rialto/src/node-process/NodeInterceptors/ConsoleInterceptor.js', '/.../vendor/nesk/rialto/src/node-process/serve.js' ] }
下面安装Node依赖
npm install @nesk/puphpeteer
或者使用yarn安装Node依赖:
yarn add @nesk/puphpeteer
如果npm安装速度太慢,可以尝试更换国内npm镜像源:
npm config set registry https://registry.npm.taobao.org
插件注册选项
QueryList::use(Chrome::class,$opt1)
$opt1: 设置chrome函数别名
API
chrome($url, $options = []) 使用Chrome打开链接,返回值为设置好HTML的QueryList对象
参数$url: 要访问的网页链接地址
参数$options: 设置Puppeteer的launch()方法的选项,全部选项:puppeteer.launch([options])
用法
在QueryList中注册插件
use QL\QueryList; use QL\Ext\Chrome; $ql = QueryList::getInstance(); // 注册插件,默认注册的方法名为: chrome $ql->use(Chrome::class); // 或者自定义注册的方法名 $ql->use(Chrome::class,'chrome');
基本用法 ...
|--原 使用puppeteer报错Error:The command "'node' '/.../node_modules/@nesk/rialto/src/node-process/serve.js'
使用puppeteer报错Error:The command "'node' '/.../node_modules/@nesk/rialto/src/node-process/serve.js' '/.../vendor/nesk/puphpeteer/src/PuppeteerConnectionDelegate.js' '{"idle_timeout":60,"log_node_console":false,"log_browser_console":false}'" failed. Exit Code: 1
使用puppeteer报错Error:The command "'node' '/.../node_modules/@nesk/rialto/src/node-process/serve.js' '/.../vendor/nesk/puphpeteer/src/PuppeteerConnectionDelegate.js' '{"idle_timeout":60,"log_node_console":false,"log_browser_console":false}'" failed. Exit Code: 1...