P粉0777017082023-08-29 00:16:15
我为JavaScript代码创建了一个新的js文件 script.js
// script.js const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({headless: false}); const page = await browser.newPage(); await page.goto('http://my-url.com'); const button = await page.$('button#button'); await button.evaluate( button => button.click() ); await page.waitForTimeout(5000); ... await browser.close(); })();
而在控制器中,我已经进行了更改:
$process = new Process(['path/to/node', 'path/to/script.js]); $process->run(); if(!$process->isSuccessful()) { throw new ProcessFailedException($process); } $output = $process->getOutput(); $errors = $process->getErrorOutput();
这对我有用