Tuesday 18 April 2017

Iterate through multiple pages within the same site using Cheerio and Node JS

Hi guys,I am having trouble scraping data from a site with multiple pages. I can scrape through the first page but not sure how to scrape through the following 10 pages on same site?script.jsvar express = require('express'); var path = require('path'); var request = require('request'); var cheerio = require('cheerio'); var app = express(); var port = 8080; var url = "https://www.example.com"; request(url, function(err, resp, body){ var $ = cheerio.load(body); if(err){ console.log(err); }else{ $('#div').find('li').each(function(i, element){ // everything i want to scrape i do under here console.log(element); }); } }); app.listen(port); console.log("server running on port "+ port);

Submitted April 19, 2017 at 04:26AM by tht_chico

No comments:

Post a Comment