【发布时间】:2020-08-24 19:35:54
【问题描述】:
问题已通过从实际浏览器添加 cookie 得到解决。
我正在尝试从这个网站https://shop.coles.com.au/a/richmond-south/specials/search/half-price-specials 获得半价产品。该网站由 AngularJS 渲染,所以我尝试使用 puppeteer 进行数据抓取。
- headless 是假的,只是显示一个空白页面
- headless 是真的,它作为图像抛出异常Error while running with headless browser
const puppeteer = require('puppeteer');
async function getProductNames(){
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.setViewport({ width: 1000, height: 926 });
await page.goto("https://shop.coles.com.au/a/richmond-south/specials/search/half-price-specials");
await page.waitForSelector('.product-name')
console.log("Begin to evaluate JS")
var productNames = await page.evaluate(() => {
var div = document.querySelectorAll('.product-name');
console.log(div)
var productnames = []
// leave it blank for now
return productnames
})
console.log(productNames)
browser.close()
}
getProductNames();
P/S:在研究这个问题时,我发现网页实际上是 console.log 取出每个页面的数据,但我无法跟踪请求。如果你能告诉我它有多棒。
【问题讨论】:
标签: javascript node.js web-scraping web-crawler puppeteer