【问题标题】:Json Data Request from Web using Python使用 Python 从 Web 请求 Json 数据
【发布时间】:2018-10-23 08:22:33
【问题描述】:

我是 python 新手。现在我正在研究使用请求进行网络抓取,但我被困在下面的链接中以 json 格式获取数据表

http://hyd-app.rid.go.th/hydro3d.html

任何人都可以提供帮助 谢谢

【问题讨论】:

    标签: json python-3.x web-scraping


    【解决方案1】:

    如果您右键单击然后在 Chrome 或 Firefox 中进行检查,您可以在网络选项卡下看到对不同 URL 的 XHR 请求。您可以像这样直接访问 URL(只需将“数据”有效负载更新为您想要的)

    import requests
    import json
    
    url = "http://hyd-app.rid.go.th/webservice/getDailyWaterLevelListReport.ashx?option=2"
    headers = {'Accept': 'application/json'}
    data = {"DW[UtokID]": "3",
    "DW[TimeCurrent]": "23/10/2561",
    "_search": "false",
    "nd": "1540287188732",
    "rows": "1000",
    "page": "1",
    "sidx": "indexcount",
    "sord": "asc"}
    
    r = requests.post(url, data = data, headers = headers)
    with open('data.json', 'w') as outfile:
        json.dump(r.json(), outfile)
    

    我已将它转储到一个文件中,因为我的终端不会显示带有它使用的编码的 json。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-06
      • 2022-01-23
      • 2020-11-15
      • 2023-03-23
      相关资源
      最近更新 更多