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();
這對我有用