我想获取价格和卖家数据,但我只获取第一行,为什么?我正在尝试学习js,但在这里我花了很多时间,请帮助。
我从不同的站点获取代码并根据我的要求修改它,但仍然无法正常工作
Puppeteer js、nodejs
var url = 'https://www.amazon.co.uk/gp/offer-listing/3770436385/ref=olp_f_used?ie=UTF8&f_new=true&f_usedAcceptable=true&f_usedGood=true&f_used=true&f_usedLikeNew=true&f_usedVeryGood=true';
const puppeteer = require('puppeteer');
(async function main(){
try{
const browser = await puppeteer.launch({headless: false });
const page = await browser.newPage();
page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/67.0.3372.0 Safari/537.36');
await page.goto(url);
await page.waitForSelector('div.navFooterLine:nth-child(6)');
const sections = await page.$$('.olpOffer');
console.log(sections.length);
for (const section of sections){
const result = await page.evaluate(() => {
// let amaOffer = document.querySelector('#olpOfferList img').innerText;
// let amaPrice = document.querySelector('#olpOfferList img').innerText;
let seller = document.querySelector('.a-text-bold a').innerText;
let price = document.querySelector('.olpOfferPrice').innerText;
return {
// amaOffer,
seller,
price
}
} )
console.log(result);
}
} catch (e) {
console.log('Our error', e);
}
})();
qq_笑_17
互换的青春
相关分类