jquery - Get nested selector without classes nor id's -


i trying scrape website , don't know how selectors want. using function:

function scrapedata(urls) { var data = []; var urlpromises = urls.map(function(url) {     return request(url).spread(function(response, html){         if (response.statuscode == 200) {             var $ = cheerio.load(html);             var elements = $('.iframeprincipal').toarray();             // items scrape             return elements.map(function(el, index){                 var title = $(el).find('h2').text().replace(/^\s+|\s+$/g, "");                 var stock = $('#formasp > table:nth-child(4) > tbody > tr > td > table > tbody > tr:nth-child(2) > td.iframeprincipal > table > tbody > tr > td > table > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(3) > td > table > tbody > tr > td').html();                 var price = parsefloat($(el).find('td:nth-child(1)').text().replace(/\€|,/g, '.'));                 // push items data array                 return {title: title, stock: stock, price: price, date: date};             });         }         else {             return [];         }     }, function(error){         console.log("error");         return [];     }); }); return promise.all(urlpromises).then(flatten); } 

var title works charm. var stock doesn't, css path copypasted, , var price previous website, anyway dont know hot either. getting "null".

this example of url scrape : site scrape

ok, looking inspectors path instead of real code one.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -