functions

.click()

In this case, we want to click the second button on ul.filter-list


const crawler = new PlaywrightCrawler({
	  requestHandler: async ({ page, infiniteScroll }) => {


		//get top sales first
		await page.waitForSelector(".filter-list ");
		await page.$$eval(".filter-list > li > button", (els) => {
		  return els.map(async(el,i) => {
			  if(i===1)await el.click()
			});
		});
});

await crawler.run([
"https://show.1688.com/pinlei/industry/pllist.html?&sceneSetId=854&sceneId=5982&bizId=8704&adsSearchWord=%E7%81%AF%E7%BD%A9&category=1032772",
"https://show.1688.com/pinlei/industry/pllist.html?&sceneSetId=854&sceneId=3789&bizId=6295&adsSearchWord=%E5%95%86%E5%9C%BA%E7%85%A7%E6%98%8E%E5%B0%84%E7%81%AF&category=1034970",
])

getAttritbuteNames()

In this case, we want to know the attribute names that exist inside a certain class

 await page.waitForSelector(".offer-img");
        const image = await page.$$eval(".offer-img", (els) => {
        return els.map((el) => el.firstElementChild.getAttributeNames());
        console.log(image
 });

getAttribute()

In this case, we already know that we want to get the value of <img src=""/>

await page.waitForSelector(".offer-img");
const image = await page.$$eval(".offer-img", (els) => {
  return els.map((el) => el.firstElementChild.getAttribute("src"));
});
console.log(image)

In this case, we already know that we want to get the value of <a href=""/> in .offer class

await page.waitForSelector(".offer");
const link = await page.$$eval(".offer", (els) => {
  return els.map((el) => {
	const url = el.getAttribute("href");
	return url;
  });
});
console.log(link)

In this case, we already know that we want to get the value of <img src=""/> in the FIRST element .offer-image class

await page.waitForSelector(".offer-img");
const image = await page.$$eval(".offer-img", (els) => {
    return els.map((el) => el.firstElementChild.getAttribute("src"));
});
console.log(image)

infinite scroll

const crawler = new PlaywrightCrawler({
	  requestHandler: async ({ page, infiniteScroll }) => {
		await infiniteScroll({
		  timeoutSecs: 0,
		  waitForSecs: 2,
		  scrollDownAndUp: true,
		});
})

await crawler.run([
"https://show.1688.com/pinlei/industry/pllist.html?&sceneSetId=854&sceneId=5982&bizId=8704&adsSearchWord=%E7%81%AF%E7%BD%A9&category=1032772",
"https://show.1688.com/pinlei/industry/pllist.html?&sceneSetId=854&sceneId=3789&bizId=6295&adsSearchWord=%E5%95%86%E5%9C%BA%E7%85%A7%E6%98%8E%E5%B0%84%E7%81%AF&category=1034970",
])

Get to the next page with enque link

requestHandler: async ({ page, enqueueLinks }) => {
  await page.waitForSelector(".css-f9wzo6");
  await enqueueLinks({
    selector: ".css-f9wzo6",
    label: "LIST",
  });
});

Last updated

Was this helpful?