一开始的代码
ips =['11.11.1.2']
result = requests.get('https://qifu-api.baidubce.com/ip/geo/v1/district?ip=11.11.1.2',verify=False)
print(result.text)
为了解决证书问题,加了verify=False 但还是显示报错,后面加了本机fiddler端口地址就成功了
ips =['11.11.1.2']
result = requests.get('https://qifu-api.baidubce.com/ip/geo/v1/district?ip=11.11.1.2',verify=False,proxies={
'http':'本机ip:8888',
'https':'本机ip:8888'})
print(result.text)
成功抓包!结果如下
{"code":"Success","data":{"continent":"北美洲","country":"美国","zipcode":"43215","timezone":"UTC-5","accuracy":"城市","owner":"美国国防部网络信息中心","isp":"美国国防部网络信息中心","source":"数据挖掘","areacode":"US","adcode":"","asnumber":"749","lat":"","lng":"","radius":"","prov":"俄亥俄州","city":"哥伦布","district":""},"charge":false,"msg":"查询成功","ip":"11.11.1.2","coordsys":"WGS84"}
Process finished with exit code 0
如果想输出data里面的某个字段,比如“country”,就把print改成以下形式
print(result.json()['data']['country'])