首页 > 解决方案 > 使用 puppeteer 抓取 wish.com

问题描述

有人在抓取wish.com上有运气吗?

我试过了,但严重的是它比预期的要难。

从登录页面它总是给我一个错误超时。

需要帮忙。

const puppeteer = require('puppeteer');

(async () => {
        const browser = await puppeteer.launch();
        const page = await browser.newPage();

        await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36');
        await page.setViewport({width:960,height:768});
        await page.goto('https://www.wish.com', {waitUntil: 'load', timeout: 100000})
        
        const emailInput = '[placeholder="Email Address"][autocomplete="email"]'
        const emailWords = 'test_account@gmail.com'
        await page.waitForSelector( emailInput, { timeout: 0 })
        await page.focus(emailInput)
        await page.keyboard.type(emailWords)

        const passwordInput = 'input[placeholder="Password"][autocomplete="current-password"]'
        const passwordWords = 'testpassword'
        await page.waitForSelector( passwordInput, { timeout: 0 })
        await page.focus(passwordInput)
        await page.keyboard.type(passwordWords)

        await page.screenshot({ fullPage: true, path: 'wish.png' })

        await Promise.all([
            page.keyboard.press('Enter'),
            page.waitForNavigation({ waitUntil: 'networkidle0', timeout: 1000000 }),
        ])

        await page.screenshot({ fullPage: true, path: 'wish2.png' })

        await page.goto('https://www.wish.com/search/nike', {waitUntil: 'load', timeout: 100000})

        //await browser.close();
        (async() => {
            browser.close();
          })();
})();

标签: puppeteer

解决方案


是的,如果您的网络速度较低,则可能会发生这种情况。我通过使用此代码解决了问题。

await page.waitFor(10000) 设置等待 10 秒以连接网络。您可以使用 waitFor 函数设置任何秒数

希望这对您有很大帮助。

问候


推荐阅读