node.js - Puppeteer 无法在 GoormIDE 中启动浏览器进程
问题描述
const puppeteer = require ('puppeteer');
async function scrapeA (url) {
return new Promise (async (resolve, reject) => {
try{
**const browser = await puppeteer.launch();**
const page = await browser.newPage();
await page.goto(url)
page.$eval('#city', elem => elem.click());
const [el] = await page.$x('//*[@id="content"]/div[1]/div[2]/h1/a');
const txt1 = await el.getProperty('innerText');
const nameA = await txt1.jsonValue();
const [el2] = await page.$x('//*[@id="offerPrice_328504"]');
const txt2 = await el2.getProperty('innerText');
const priceA = await txt2.jsonValue();
const [el3] = await page.$x('//*[@id="inventoryTableBody"]/div[5]/div[3]/span[1]');
const txt3 = await el3.getProperty('innerText');
const quantA = await txt3.jsonValue();
const [el4] = await page.$x('//*//*[@id="inventoryTableBody"]/div[5]/div[2]/text()[1]');
const txt4 = await el4.getProperty('textContent');
const locA = await txt4.jsonValue();
console.log({nameA},{priceA},{quantA},{locA});
browser.close();
return resolve();
} catch (e) {
return reject(e);
}
})
}
scrapeA(webpageurl);
这段代码在我的代码编辑器中工作。我正在尝试对此进行一些后端处理,所以我将它移到了我的 GoormIDE 中。浏览器进程无法启动
我已经尝试了 2 个不同软件包的所有组合:puppeteer 和 puppeteer-core
和 3 种不同的启动设置:
const browser = await puppeteer.launch();
const browser = await puppeteer.launch({headless: false});
const browser = await puppeteer.launch({ignoreDefaultArgs: ['--disable-extensions']});
解决方案
使用安装缺少的包
apt-get install gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libgbm-dev
试试这个
const browser = await puppeteer.launch({ args: ['--no-sandbox'] });
推荐阅读
- java - java 只读字符由 System.in
- python - Python:使用芹菜处理多个服务器上的参数列表
- perl - EnsEMBL Perl API 连接错误
- java - Java 多态性:为什么会返回错误?
- mysql - Rails 5 Left Outer Join 与 WHERE 查询相结合
- java - 如何从 CMD 读取所有输出以获取日志
- python - 删除置换多索引的重复项
- sql - 需要减去直到值达到限制/预测库存何时用完
- coldfusion - 尝试在 ColdFusion / ColdBox 应用程序之间共享会话时重命名应用程序时出错
- macos - 在 MAC OS High sierra 中将文本转换为蛇形大小写到驼峰大小写