Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
百度地图书店搜索结果抓取
function getPages( total ) {
var url = "http://ditu.baidu.com/?newmap=1&reqflag=pcmap&biz=1&pcevaname=pc2&da_par=direct&qt=s&from=webmap&da_src=pcmappg.poi.page&wd=%E4%B9%A6%E5%BA%97&c=131&sug=0&ie=utf-8&wd2=&l=12&src=7&pn=1&db=0&on_gel=1&gr=3&addr=0&nn=";
var start = 0, urls = [];
do {
urls.push( url + start );
start += 10;
} while( start < total );
return urls;
}
function getScript(url) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest;
xhr.open("GET", url, true);
xhr.responseType = "json";
xhr.onload = function() {
xhr.status !== 200 ? reject( Error( xhr.statusText ) ) : resolve( xhr.response );
}
xhr.onerror = function() {
reject( Error( xhr.statusText ) );
}
xhr.send(null);
})
}
var addrs = [];
getPages( 760 ).map( getScript ).reduce(function(seq, json) {
return seq.then(function(){return json}).then(function(pos) {
console.log( pos );
addrs = addrs.concat( pos.content );
return addrs;
})
}, Promise.resolve() ).then(function() {
console.log( addrs );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.