def ipinfocip(ip):
# 获得 输入框中的信息
url = "http://www.cip.cc/%s" % ip
# 模拟浏览器请求网络
headers={‘User-Agent‘ : ‘Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0
request = urllib2.Request(url, headers=headers)
response = urllib2.urlopen(request)
content = response.read()
# print content
#利用正则表达式 获取网页中的内容
‘‘‘
地址: \xe5\x9c\xb0\xe5\x9d\x80\t:
运营商: \xe8\xbf\x90\xe8\x90\xa5\xe5\x95\x86\t:
数据二: \xe6\x95\xb0\xe6\x8d\xae\xe4\xba\x8c\t:
数据三: \xe6\x95\xb0\xe6\x8d\xae\xe4\xb8\x89\t:
‘‘‘
# res = r‘
(.*?)‘
res = r‘\xe6\x95\xb0\xe6\x8d\xae\xe4\xba\x8c\t: (.*?)\n\n\xe6\x95\xb0\xe6\x8d\xae\xe4\xb8\x89\t:‘
items = re.findall(res, content, re.S | re.M)
addr = items[0].replace(" | ", "")
data = {
"ip": ip,
"info": "%s" % addr,
"info2": "",
}
return data