【发布时间】:2020-03-12 18:14:49
【问题描述】:
我在尝试从 coinfarm.online 抓取某些内容时总是遇到错误。所以我要最后的价格。当我在浏览器中使用控制台尝试它时,它运行良好,但使用此脚本时,我总是收到错误或 null。
const puppeteer = require("puppeteer");
(async () => {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto("https://coinfarm.online", { waitUntil: "load", timeout: 0 });
const example = await page.evaluate(
() => document.querySelector("#xbt_last").innerText
);
console.log("Price: " + example);
await browser.close();
})();
我也用 XPath 尝试过,但也没有用....
【问题讨论】:
-
也许
await page.waitForSelector('#xbt_last')?
标签: javascript node.js puppeteer