puppeteer - 使用 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();
})();
})();
解决方案
是的,如果您的网络速度较低,则可能会发生这种情况。我通过使用此代码解决了问题。
await page.waitFor(10000) 设置等待 10 秒以连接网络。您可以使用 waitFor 函数设置任何秒数
希望这对您有很大帮助。
问候
推荐阅读
- javascript - 如何将 JSON 对象从 Javascript 传递到 Python CGI 脚本
- javascript - 在 Node.js 中声明多个 module.exports,TypeError: Router.use() requires a middleware function but got a Object
- azure - 如何在 Azure 中创建负载均衡器(免费试用)
- spring-boot - Spring批处理集成:java.lang.ClassCastException:org.springframework.integration.file.FileReadingMessageSource 无法转换为 java.io.File
- python-3.x - 名称和数据的多个元组中的数据统计
- asp.net-mvc - 为什么我们在 MVC 表单认证中使用 setAuthCookies
- arrays - Robot Framework - 如何在行列表中获取值
- python - views.py 中的 Order_by BooleanField 不起作用。蟒蛇,姜戈
- blockchain - Corda 中的数字权证
- c - 不同的数据类型:如何将它们全部存储在一个字符串中以及如何为其分配动态内存?