【问题标题】:is there a way to use require.js for using puppeteer in a web page?有没有办法使用 require.js 在网页中使用 puppeteer?
【发布时间】: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


    【解决方案1】:

    没有。

    require.js 库可以让你在 Web 浏览器中使用 CommonJS 模块系统。

    它不能让你使用 Node.js 而不是浏览器提供的 API(因此不能让你使用依赖于这些 API 的模块)。

    【讨论】:

    • 非常感谢。还有其他方法可以制作爬虫网页吗?!
    • 浏览器中的安全限制使其几乎不可能实现。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-09
    • 2020-12-31
    • 2022-01-26
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多