0

我一直在尝试在几个不同的网站上创建一个股票刮板作为个人项目。最近我在这里涉足使用 Puppeteer 来处理通过虚拟无头浏览器进行的抓取。但是,当尝试抓取 Walmart 时,它不断地给我一个 UnhandledPromiseRejectionWarning: TimeoutError: waiting for XPath。我尝试了一些调试,但我不明白发生了什么。我使用此语法的所有其他网站都在运行,所以我想我会要求一些输入。

async function scrapeWalmart(url) {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto(url);

    await page.waitForXPath('//*[@id="blitzitem-container"]/div/div/div/div'); // Destructuring the url
    const [la] = await page.$x('//*[@id="blitzitem-container"]/div/div/div/div');
    const webText = await la.getProperty('textContent');
    const rawWebText = await webText.jsonValue();
    webTextString = rawWebText.toString();
    console.log("Stock on Walmart: \n");
    console.log(rawWebText + "\n");
    browser.close();
}
4

0 回答 0