淘宝的ip地址库

来源:互联网 发布:知乎阅读 编辑:程序博客网 时间:2024/04/30 07:23

http://ip.taobao.com/instructions.php

接口说明

==============================================================================

以下转自 zcqshine 的博客


利用python抓取淘宝提供的ip库信息并保存.

淘宝ip库网站:http://ip.taobao.com

淘宝提供的API地址为:http://ip.taobao.com/service/getIpInfo.php?ip=

这个接口提供的QPS=10

以下为用python简单实现(剔除了私有ip地址段,在判断的时候后也只取了IP段的前三节,第四节统一设置为0,因为只要根据前三段就可以判断ip的归属地信息了)

Python代码  收藏代码
  1. # -*- decoidng:utf-8 -*-  
  2. from urllib import request  
  3. import time  
  4.   
  5. def writefile(L=[]):  
  6.     with open('ip.txt','a') as f:  
  7.         for s in L:  
  8.             f.write(s)  
  9.             f.write('\n')  
  10.         f.close()  
  11.   
  12.   
  13. l=[]  
  14. a = 1  
  15. while a < 256:  
  16.     if a == 10:  
  17.         a=a+1  
  18.         continue  
  19.     b=0  
  20.     while b < 256:  
  21.         if a == 172 and b>15 and b<32:  
  22.             b=b+1  
  23.             continue  
  24.         if a == 192 and b==168:  
  25.             b = b + 1  
  26.             continue  
  27.         c=0  
  28.         while c < 256:  
  29.             ip = str(a) + "."+ str(b) + "." + str(c) + "." + "0"  
  30.             url='http://ip.taobao.com/service/getIpInfo.php?ip='+ip  
  31.             with request.urlopen(url)as f:  
  32.                 data = f.read()  
  33.                 l.append(str(data.decode('utf-8')))  
  34.                 if len(l) > 100:  
  35.                     writefile(l)  
  36.                     l=[]  
  37.             time.sleep(0.2)  
  38.             c=c+1;  
  39.         b=b+1  
  40.     a=a+1  
  41. if len(l)>0:  
  42.     writefile(l)  

 

 


0 0