I'm trying to grab products from ebay and open them on amazon and get the asins from the search results.
So far the script is scraping some of asins from the list of ebay titles that loops through, but then there is quite a lot of random blanks. Im guessing this may be due to if the page has fully rendered. i did try some waits but with no luck.
const puppeteer = require('puppeteer');
const URL = "https://www.amazon.co.uk/";
const selectors = {
searchBox : '#twotabsearchtextbox',
productLinks: 'span.a-size-base-plus.a-color-base.a-text-normal',
productTitle: '#productTitle'
};
let browser;
(async () => {
browser = await puppeteer.launch( {headless: false});
const page = await browser.newPage();
await page.goto('https://www.ebay.co.uk/sch/jmp_supplies/m.html?_trkparms=folent%3Ajmp_supplies%7Cfolenttp%3A1&rt=nc&_trksid=p2046732.m1684');
const ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36";
await page.setExtraHTTPHeaders({"Accept-Language": "en-US,en;q=0.9"});
await page.setUserAgent(ua);
//Get product titles from ebay
const grabTitles = await page.evaluate(() =>{
const itemTitles = document.querySelectorAll('#e1-11 > #ResultSetItems > #ListViewInner > li > .lvtitle > .vip');
var items = []
itemTitles.forEach((tag) =>{
items.push(tag.innerText)
})
return items
})
for (const title of grabTitles) {
const page = await browser.newPage();
await page.goto("https://www.amazon.co.uk/");
await page.type("#twotabsearchtextbox", title);
await Promise.all([
await page.keyboard.press("Enter"),
page.waitForNavigation(),
]);
const attr = await page.$$eval("div.s-result-item.s-asin.sg-col-0-of-12.sg-col-16-of-20.sg-col.s-widget-spacing-small.sg-col-12-of-16",
el => el.map(x => x.getAttribute("data-asin")));
console.log(attr.slice(0, 5));
}
})()
.catch(err => console.error(err))
.finally(() => browser?.close())
;