# -*- coding: utf-8 -*-
import requests
import json
'''
两个获取ip的地理信息的接口:
http://freeapi.ipip.net/
http://ip-api.com/json/
'''
# 获取本地ip
ipAddress = requests.get('http://ip.42.pl/raw',).text
print(ipAddress)
response = requests.get("http://ip-api.com/json/" + ipAddress).text
print(type(response))
response = json.loads(response) # 将网页的json格式的字符串数据转成字典
print(type(response))
print(response["countryCode"])
python实现根据ip获取归属地理信息
最新推荐文章于 2024-08-15 08:55:59 发布