使用来自网站的查询获取数据

Get data by using a query from a website

使用Python或R,如何将以下网站的数据下载成dataframe或类似格式?我认为这不是网络抓取,而是使用查询请求获取数据。

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

你不需要制作网络抓取工具,我观察了对该站点的所有请求,然后我用我的工具解码了这些请求....,请参阅:

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)

注意:请不要在非法或骇人听闻的情况下使用它。