【问题标题】:Pupeteer execute command in Devtools ConsolePuppeteer 在 Devtools 控制台中执行命令
【发布时间】:2022-01-27 05:50:08
【问题描述】:

所以我有一行可以手动粘贴到浏览器中的 Devtools 控制台中。有没有办法让 pupeteer 执行它?搜索后我没有找到任何东西,对不起,如果已经回答了,我是新手。

对于那些关心购买物品清单的人来说,例如:

BuyMarketListing('listing', '3555030760772417847', 730, '2', '24716958303')

【问题讨论】:

标签: javascript node.js web-scraping google-chrome-devtools chrome-devtools-protocol


【解决方案1】:

您似乎在寻找page.evaluate()Here is a link to the Puppeteer's documentation for it。您可以传入一个字符串或一个匿名函数,其中包含您要在页面中评估的行。

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');

  await page.evaluate(() => { insert lines here }); // page.evaluate() should run the lines in the browser console

  await browser.close();
})();

【讨论】:

    猜你喜欢
    • 2016-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-28
    • 1970-01-01
    • 2015-04-06
    • 1970-01-01
    相关资源
    最近更新 更多