• 欢迎光临~

python 鹰图平台api json数据处理

开发技术 开发技术 2022-07-18 次浏览

示例

url = "https://hunter.qianxin.com/openApi/search?api-key=c5ccb10c470ef839c132cf0d578e5da479db4e8a79756dd150fc9f75bcfdd6ab&search=d2ViLmJvZHk9Ikhpa3ZzaW9uIg==&page=1&page_size=10&is_web=1&status_code=200&start_time=2022-06-19+00%3A00%3A00&end_time=2022-07-18+23%3A59%3A59"

r = requests.get(url)
print(r.json())

	

参考
https://hunter.qianxin.com/home/helpCenter?r=5-1-2

参数:
search
经过符合RFC 4648标准的base64url编码编码后的搜索语法,语法规则见首页-查询语法
is_web
资产类型,1代表”web资产“,2代表”非web资产“,3代表”全部“
status_code

状态码列表,以逗号分隔,如”200,401“
page

页码

api返回json格式示例数据

{
  "code": 200,
  "msg": "success",
  "data": {
    "total": 1,
    "time": 1,
    "arr": [
      {
        "web_title": "web_title",
        "ip": "127.0.0.1",
        "port": 80,
        "base_protocol": "tcp",
        "protocol": "http",
        "domain": "123456.cn",
        "component": [
          {
            "name": "nginx",
            "version": "1.6"
          }
        ],
        "url": "http://123456.cn",
        "os": "linux",
        "country": "中国",
        "province": "北京",
        "city": "北京",
        "updated_at": "2021-01-01 00:00:00",
        "status_code": 200,
        "number": "",
        "company": "北京xxx公司",
        "is_web": "是",
        "is_risk": "",
        "is_risk_protocol": "",
        "as_org": "PDR",
        "isp": "运营商信息",
        "banner": "banner"
      }
    ],
    "consume_quota": "消耗积分:20",
    "rest_quota": "今日剩余积分:77"
  }
}

分析 json_data['data']['arr']里是需要的数据,如此历遍:
url_list = [arr['url'] for arr in json_data['data']['arr']]
api获取数据后python处理:

url = "https://hunter.qianxin.com/openApi/search?api-key=c5ccb10c470ef839c132cf0d578e5da479db4e8a79756dd150fc9f75bcfdd6ab&search=d2ViLmJvZHk9Ikhpa3ZzaW9uIg==&page=1&page_size=10&is_web=3&status_code=200&start_time=2022-06-19+00%3A00%3A00&end_time=2022-07-18+23%3A59%3A59"

r = requests.get(url)
json_data = r.json()
print(r.json())

# for arr in json_data['data']['arr']:
#     print(arr['url'])

url_list = [arr['url'] for arr in json_data['data']['arr']]
ip_list = [arr['ip'] for arr in json_data['data']['arr']]
print(url_list)
print(ip_list)

with open("result.txt", "a", encoding='utf-8') as f:
    for i in url_list:
        f.write(i+'n')
    f.write("n")
程序员灯塔
转载请注明原文链接:python 鹰图平台api json数据处理
喜欢 (0)