本文共 1073 字,大约阅读时间需要 3 分钟。
思路:ip---->获得经纬度------>利用爬虫去爬取ip的地址
#!/usr/bin/env python# _*_ coding:utf-8 _*_# 导入相应模块import geoip2.databaseimport requests,redef Iplocation(ip): response = geoip2.database.Reader("./GeoLite2-City.mmdb").city(ip) headers = { 'User-Agent': 'Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', 'Hosts': 'www.gpsspg.com', 'Referer':'http://www.gpsspg.com/iframe/maps/qq_161128.htm?mapi=2', } url = "http://www.gpsspg.com/apis/maps/geo/?output=jsonp&lat=%s000000&lng=%s000000&type=0&callback=jQuery110207785323396673127_1522316918197&_=1522316918198" % (response.location.latitude,response.location.longitude) try: return re.findall("address\"\:\"(.+?)\"", requests.get(url,headers=headers).text)[0] except Exception as e: return eif __name__ == '__main__': ip = "117.87.177.35" print Iplocation(ip)
C:\Python27\python.exe C:/Users/Administrator/PycharmProjects/正则/Iplocation.py江苏省南京市鼓楼区湖南路街道傅厚岗社区南方向Process finished with exit code 0
(GeoLite2-City.mmdb)
转载地址:http://irrwa.baihongyu.com/