lib/picsearch-images-scraper.js
function(url) {
		return new Promise(function (resolve) {
			self.roptions.url = url;
			request(self.roptions, function (err, response, body) {
				if (!err && response.statusCode === 200) {
					var $ = cheerio.load(body);

					// no results
					if (!$('.result').length) {
						return resolve(result);
					}
					
					$('.result').each(function() {
						var href = $(this).find('a').attr('href');
						if(href.toString().indexOf("http") !== 0) {
							result.push(base + href); 							
						} else {
							result.push(href); 							
						}
					});

					if (num && result.length > num) {
						return resolve(result.slice(0,num));
					}

					// search for current page and select next one
					var page = $('#nextPage').attr('href');
					if (page) {
						resolve(nextPage(base + page));
					}
					else {
						resolve(result);
					}
				} else {
					resolve(result)
				}
			});
		});
	}
function(url) {
		return new Promise(function (resolve) {
			self.roptions.url = url;
			request(self.roptions, function (err, response, body) {
				if (!err && response.statusCode === 200) {
					var $ = cheerio.load(body);

					// no results
					if (!$('.result').length) {
						return resolve(result);
					}
					
					$('.result').each(function() {
						var href = $(this).find('a').attr('href');
						if(href.toString().indexOf("http") !== 0) {
							result.push(base + href); 							
						} else {
							result.push(href); 							
						}
					});

					if (num && result.length > num) {
						return resolve(result.slice(0,num));
					}

					// search for current page and select next one
					var page = $('#nextPage').attr('href');
					if (page) {
						resolve(nextPage(base + page));
					}
					else {
						resolve(result);
					}
				} else {
					resolve(result)
				}
			});
		});
	}
function ( url ) { return new Promise ( function ( resolve ) { self . roptions . url = url ; request ( self . roptions , function ( err , response , body ) { if ( ! err && response . statusCode === 200 ) { var $ = cheerio . load ( body ) ; // no results if ( ! $ ( '.result' ) . length ) { return resolve ( result ) ; } $ ( '.result' ) . each ( function ( ) { var href = $ ( this ) . find ( 'a' ) . attr ( 'href' ) ; if ( href . toString ( ) . indexOf ( "http" ) !== 0 ) { result . push ( base + href ) ; } else { result . push ( href ) ; } } ) ; if ( num && result . length > num ) { return resolve ( result . slice ( 0 , num ) ) ; } // search for current page and select next one var page = $ ( '#nextPage' ) . attr ( 'href' ) ; if ( page ) { resolve ( nextPage ( base + page ) ) ; } else { resolve ( result ) ; } } else { resolve ( result ) } } ) ; } ) ; }
max it to 2000 for default because we can go on indefinitely
max it to 2000 for default because we can go on indefinitely