zoukankan      html  css  js  c++  java
  • 查询最新的邮编地区

    以下是爬取最新的邮编地区的代码

    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()
    

      

  • 相关阅读:
    AC自动机 HDOJ 2222 Keywords Search
    AC自动机 HDOJ 5384 Danganronpa
    贪心 HDOJ 5385 The Path
    区间DP UVA 10739 String to Palindrome
    区间DP UVA 10453 Make Palindrome
    素数专题
    判素数+找规律 BestCoder Round #51 (div.2) 1001 Zball in Tina Town
    DP专题
    贪心+模拟 ZOJ 3829 Known Notation
    概率DP ZOJ 3822 Domination
  • 原文地址:https://www.cnblogs.com/xuan52rock/p/11177292.html
Copyright © 2011-2022 走看看