以下是爬取最新的邮编地区的代码
function top10(){ mAjax('http://www.ip138.com/post/search.asp?zone='+arr[0]+'&action=zone2area',function(ret){ console.log(ret); },function(err){ console.log('errerr'); },'','get') } var obj={}; function mAjax(url,success,fail,data,type){ var xhr = new XMLHttpRequest(); xhr.open(type, url, true); xhr.responseType = "text"; xhr.onload = function() { if (this.status == 200) { var str=xhr.responseText; var start = str.indexOf('<TABLE width=349 border="1" style="border-collapse:'); var end = str.indexOf('</TABLE>',start) $('#BAIDU_DUP_fp_wrapper').css({"visibility":"visible","display":"block"}); $('#BAIDU_DUP_fp_wrapper').width(500); $('#BAIDU_DUP_fp_wrapper').height(500); $('#BAIDU_DUP_fp_wrapper').html(str.substring(start,end+8)); //var aa=$('#BAIDU_DUP_fp_wrapper tr:eq(1)').text(); //if(aa.indexOf('更详细的...')==-1)console.log(arr[0]+" == "+aa); $('#BAIDU_DUP_fp_wrapper tr:gt(1)').each(function(i,o){ var a=$(o).text(); if(a.indexOf('更详细的...')==-1){ var b=a.split(':'); obj[b[0].replace('◎ ','').replace(' 邮编','')]=a; //console.log(a) } }); //var obj=xhr.getAllResponseHeaders();//xhr.responseText; //success&&success(obj) } arr.shift(); if(arr.length>0)top10(); else{ for(var k in obj){ console.log(obj[k]) } } } xhr.send(data); } var arr=[]; for(var i=1;i<1000;i++){ arr.push('0'+i); } top10()