I have the following:
const express = require('express');
const app = express();
const port = 3000;
const rp = require('request-promise');
const cheerio = require('cheerio');
const options = {
uri: `https://www.zoopla.co.uk/for-sale/details/51403409?search_identifier=620f645adbd75033ae2faf2cffdcfc3a`,
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
},
transform: function (body) {
return cheerio.load(body);
}
};
rp(options)
.then(($) => {
for (var i = 0; i < $('img').length; i++) {
console.log($('img')[i].attribs.src)
}
})
.catch((err) => {
console.log(err);
});
app.get('/', (req, res) => res.send('Hello World!'));
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
Although the class is in the mark up the array under the page /results is returning empty.
I am thinking that the img classes are added dynamically that's possibly why are not getting picked up.
Is there a way around that if that's the case?
UPDATE
I have updated the code however I am getting not the expected result:
I would expect to find urls of .png or .jpg
2nd UPDATE