脚本简单,找到一个免费的IP 查询接口不容易
#-*-coding:utf-8-*-
import requests
import csv
import re
header = {
‘User-Agent‘:‘Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0‘
}
with open(‘hwip.csv‘,‘r‘) as f:
dataip = csv.reader(f)
for row in dataip:
if(row == ‘null‘):
continue
else:
#url = ‘https://www.ip138.com/iplookup.asp?ip=‘+str(row[0])+‘&action=2‘
url = ‘http://whois.pconline.com.cn/ipJson.jsp?ip=‘+str(row[0])
html = requests.get(url=url,headers=header)
html = html.content.decode(‘gbk‘).encode(‘utf-8‘)
#print(html)
address1 = html.find("addr")
address2 = html.find("regionNames")
address = html[address1-3:address2-2]
print (‘{0}:{1}‘.format(row[0],address))
~
原文:https://www.cnblogs.com/HelloMrLee/p/13546173.html