【发布时间】:2020-04-18 22:17:06
【问题描述】:
我在网页中使用 puppeteer 时遇到问题 我想制作一个 java 脚本刮板并将该信息传递给我的 index.html 页面 我可以在 vs 代码中使用节点,但不能在浏览器中使用它 当我尝试在 chrome 中使用代码时,它说 require 没有定义 所以经过一番挖掘后发现我必须使用 Require.js 但我不知道如何使用它 请帮帮我
这是我的代码
const puppeteer = require('puppeteer');
async function site(url) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
const [el] = await page.$x('/html/body/div[2]/div[2]/div/div/div/a[1]/div[1]/span[3]')
const txt = await el.getProperty('textContent')
const rawTxt = await txt.jsonValue();
console.log({rawTxt});
}
site('url')
【问题讨论】:
标签: javascript web puppeteer scrape