API 接口
1 2 |
https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={ip地址}&co=&resource_id=6006&t=1529809984888&ie=utf8&oe=gbk&format=json&tn=baidu |

函数 封装
1 2 3 4 5 6 7 8 9 |
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"] |
用法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
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()) |


