IonicaBizau / scrape-it

🔮 A Node.js scraper for humans.

Home Page:http://ionicabizau.net/blog/30-how-to-write-a-web-scraper-in-node-js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I get all the values of an attribute in a tag?

wxy1995 opened this issue · comments

I want to get data with the following structure:

{
    'imgUrls': [
        'https://aa.png',
        'https://bb.png',
        'https://cc.png',
     ]
}

Is there any solution?

The below will get you close and then you will have to use standard array manipulation to rebuild an array to suit your structure.

imgs: {
listItem: "div.photoContainer"
, name: "count"
, data: {
url: {
selector: "img"
, attr: "src"
}
}
}

This returns

imgs: [
{ url: 'https://img.com/123.jpg' },
{ url: 'https://img.com/1234.jpg' },
{ url: 'img.com/1235.jpg' }
],

Yes, @wayneconnolly's answer should work. Please ask questions on Stackoverflow.