生活随笔
收集整理的這篇文章主要介紹了
Python3 百度IP 查询 接口
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
API 接口
Python https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={ip地址}&co=&resource_id=6006&t=1529809984888&ie=utf8&oe=gbk&format=json&tn=baidu
| 12 | https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={ip地址}&co=&resource_id=6006&t=1529809984888&ie=utf8&oe=gbk&format=json&tn=baidu |
函數 封裝
Python class BDIPSearch: def __init__(self,ipData): self.ipData = str(ipData) def getIP(self): url = "https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=" + self.ipData + "&co=&resource_id=6006&t=1529809984888&ie=utf8&oe=gbk&format=json&tn=baidu" ipData = urllib.request.urlopen(url).read().decode("gbk") return json.loads(ipData)["data"]
| 123456789 | classBDIPSearch:def__init__(self,ipData):self.ipData=str(ipData)defgetIP(self):url="https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query="+self.ipData+"&co=&resource_id=6006&t=1529809984888&ie=utf8&oe=gbk&format=json&tn=baidu"ipData=urllib.request.urlopen(url).read().decode("gbk")returnjson.loads(ipData)["data"] |
用法
Python import urllib import json class BDIPSearch: def __init__(self,ipData): self.ipData = str(ipData) def getIP(self): url = "https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=" + self.ipData + "&co=&resource_id=6006&t=1529809984888&ie=utf8&oe=gbk&format=json&tn=baidu" ipData = urllib.request.urlopen(url).read().decode("gbk") return json.loads(ipData)["data"] if __name__ == '__main__': ipdata = BDIPSearch("203.208.60.147") print(ipdata.getIP())
| 123456789101112131415161718192021 | importurllibimportjsonclassBDIPSearch:def__init__(self,ipData):self.ipData=str(ipData)defgetIP(self):url="https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query="+self.ipData+"&co=&resource_id=6006&t=1529809984888&ie=utf8&oe=gbk&format=json&tn=baidu"ipData=urllib.request.urlopen(url).read().decode("gbk")returnjson.loads(ipData)["data"]if__name__=='__main__':ipdata=BDIPSearch("203.208.60.147")print(ipdata.getIP()) |
- zeropython 微信公眾號 5868037 QQ號 5868037@qq.com QQ郵箱
總結
以上是生活随笔為你收集整理的Python3 百度IP 查询 接口的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。