Answer the question
In order to leave comments, you need to log in
How to increase the value of a variable in a loop?
Good afternoon!
I am doing a grabber of information from the site page.
I have this code:
var request = require('request');
var cheerio = require('cheerio');
var searchTerm = 'screen+scraping';
var page_counter = 1;
var jQuery = require('jQuery');
var url = 'http://www.domofond.ru/prodazha-kvartiry-belgorod-c310?Page="'+ page_counter+1 +'"&SortOrder=Newest';
for(page_counter = 1; page_counter < 5; page_counter++) {
request(url, function(err, resp, body){
$ = cheerio.load(body);
price = $('p.pull-left.df_listingTilePrice'); //цена
opisanie_k = $('p.df_listingTileType'); //краткое
place = $('p.df_listingTileAddress'); //адрес
opisanie_full = $('div.df_listingTileDescription')//полное описание
$(price).each(function(i,price){
console.log($(price).text() + '\n');
});
$(opisanie_k).each(function(i,opisanie_k){
console.log($(opisanie_k).text() + '\n');
});
$(place).each(function(i,place){
console.log($(place).text() + '\n');
});
$(opisanie_full).each(function(i,opisanie_full){
console.log($(opisanie_full).text() + '\n');
});
});
}
Answer the question
In order to leave comments, you need to log in
The url value must be set in a loop.
var page_counter = 2, url;
while(page_counter < 6){
url = 'http://www.domofond.ru/prodazha-kvartiry-belgorod-c310?Page="'+(page_counter++)+'"&SortOrder=Newest';
//Действие с url....
}
for(var page_counter = 2, url; page_counter < 6; page_counter++){
url = 'http://www.domofond.ru/prodazha-kvartiry-belgorod-c310?Page="'+page_counter+'"&SortOrder=Newest';
//Действие с url....
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question