经常会有需求,通过IP获取位置
简单的可以通过百度搜索ip,输入ip就可以查询.
免费的IP查位置:http://freeapi.ipip.net/
# coding = utf-8
import requests
apiUrl='http://freeapi.ipip.net/' #中文免费
def ipToAddress(ipStr):
url = apiUrl + format(ipStr)
response = requests.get(url, timeout=5)
str = response.text.replace('\"', '') #去掉双引号
str = str.replace('[', '') #去掉方括号
str = str.replace(']', '')
str = str.replace(' ', '')
print(str)
return str
评论区