美文网首页
python爬取ip归属地查询接口

python爬取ip归属地查询接口

作者: 是东东 | 来源:发表于2019-08-05 16:42 被阅读0次
from faker import Faker
import requests

# 随机ip
faker = Faker('zh-CN')
ip = faker.ipv4()


def search_ip_location(ip):
    url = f'https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={ip}&resource_id=6006'
    req = requests.get(url=url)
    body = req.json()
    mes = body.get('data')[0]
    result = {'location': mes['location'], 'origip': mes['origip']}
    return result # {'location': '日本', 'origip': '192.31.197.16'}

相关文章

网友评论

      本文标题:python爬取ip归属地查询接口

      本文链接:https://www.haomeiwen.com/subject/cygmdctx.html