Home > Software engineering >  Need help scraping image from craigslist
Need help scraping image from craigslist

Time:04-25

I've tried everything I can think of. I'm able to get postUrl, date, title, price and location. If you go to enter image description here

You can get the data-ids like this:

var data_ids = $(element).children('a').attr('data-ids')

then split it to array by comma, delete first two 3: symbols and concat it like this:

`${img_base_url}/${ids}_${resolution_and_extension}`

But if you need to get URL only for first image then there is no need to create new array each time. Use substring instead (note that sometimes li don't have image at all):

if (data_ids && data_ids.includes(',')) {
    data_ids.substring(data_ids.indexOf('3:')   2, data_ids.indexOf(','))
} else if (data_ids) {
    data_ids.substring(data_ids.indexOf('3:')   2, data_ids.length)
}
  • Related