代码之家  ›  专栏  ›  技术社区  ›  ilyas

使用网站查询获取数据[已关闭]

  •  -3
  • ilyas  · 技术社区  · 8 年前

    https://www.michigantrafficcrashfacts.org/querytool/lists/0#q1;0;2016;;

    1 回复  |  直到 8 年前
        1
  •  -1
  •   DRPK    8 年前

    你不需要制作网页刮刀,我观察了该网站的所有请求,然后用我的工具解码了这些请求。。。。,请参阅:

    1) https://www.michigantrafficcrashfacts.org/qjson?q=1;0;2016;;&v=list&p=0,0:0,77|0|90|0,asc:1,asc ||90条记录作为json

    2) https://www.michigantrafficcrashfacts.org/qjson?q=1;0;2016;;&v=list&p=0,0:0,77|0|2000|0,asc:1,asc ||2000条记录为json

    import json, requests
    
    your_records = 3000  # change this record with that number you want ( that website said the max value is 312172 )
    
    URL = "https://www.michigantrafficcrashfacts.org/qjson?q=1;0;2016;;&v=list&p=0,0:0,77|0|{0}|0,asc:1,asc".format(your_records)
    
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
    
    get_data = requests.get(URL, headers=headers)
    
    raw_data = str(get_data.content, encoding="utf-8")
    
    dict_data = json.loads(raw_data)
    
    for items, values in dict_data.items():
        print(items, values)
    

    注意:请不要在非法或黑客案件中使用。

    推荐文章