Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Image src with specific class in puppeteer

I have the following code, where I store all src in an array, I would like to store only img with class name xyz

const imgs = await page.$$eval('img[src]', imgs => imgs.map(img => img.getAttribute('src')));

I tried to user filter, but I couldn't reach the right syntax to do that.

like image 377
Hatem Husam Avatar asked Nov 30 '22 21:11

Hatem Husam


1 Answers

Just add .xyz to your query string:

const imgs = await page.$$eval('img.xyz[src]', imgs => imgs.map(img => img.getAttribute('src')));
like image 196
CertainPerformance Avatar answered Dec 05 '22 13:12

CertainPerformance