mirror of
https://github.com/lijiejie/eyes.sh.git
synced 2026-09-22 01:30:43 +08:00
修复ip城市获取问题
This commit is contained in:
+2
-5
@@ -24,11 +24,8 @@ from django.utils.translation import gettext as _
|
||||
|
||||
def get_city_by_ip(ip):
|
||||
try:
|
||||
doc = requests.get('http://ip.ws.126.net/ipquery?ip=%s' % ip).text
|
||||
doc = doc[doc.find('var localAddress=')+17:].strip()
|
||||
doc = doc.replace('city', '"city"').replace('province', '"province"')
|
||||
_doc = json.loads(doc)
|
||||
city = _doc['province'] + ' ' + _doc['city']
|
||||
doc = requests.get('https://whois.pconline.com.cn/ip.jsp?ip=%s' % ip).text
|
||||
city = doc.split(' ')[0]
|
||||
except Exception as e:
|
||||
city = ''
|
||||
return city
|
||||
|
||||
Reference in New Issue
Block a user