简体   繁体   English

Python 从 XHR 请求中得到 JSON 响应

[英]Python get JSON Response from XHR Request

I've been trying for some time to build a get request using requests and other python tools, which should actually return a JSON.一段时间以来,我一直在尝试使用 requests 和其他 python 工具构建 get 请求,实际上应该返回 JSON。

To get closer to the topic, I first try to reproduce the whole thing in the browser.为了更接近主题,我首先尝试在浏览器中重现整个过程。 Thereby I already come to limits.因此,我已经到了极限。

It's about this URL: https://unverpackt-verband.de/map关于这个URL: https://unverpackt-verband.de/map

When I look at the.network analysis in Firefox, I see the desired json under Response.当我查看 Firefox 中的 .network 分析时,我在响应下看到了所需的 json。 But the Request section is empty.但是请求部分是空的。 在此处输入图像描述

Now I would appreciate help on how to find/build a suitable request to get and process this JSON in an automated way using python.现在,我将感谢有关如何查找/构建合适的请求以使用 python 以自动方式获取和处理此 JSON 的帮助。


EDIT what has been tried so far:编辑到目前为止已经尝试过的内容:


requests.get("https://api.unverpacktverband.de/map").json() Outcome: "TooManyRedirects: Exceeded 30 redirects." requests.get("https://api.unverpacktverband.de/map").json() 结果:“TooManyRedirects:超过 30 个重定向。” Error错误

I'm not sure if you're looking for the following?我不确定您是否正在寻找以下内容?

import requests
import pandas as pd


headers = {'accept': 'application/json, text/plain, */*',
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.79 Safari/537.36'
}

url = 'https://api.unverpackt-verband.de/map'

r = requests.get(url, headers=headers)

df = pd.json_normalize(r.json())
print(df)

Result in terminal:终端结果:

    id  type    lat lng
0   1985    storeNoMember   47.558307   9.709220
1   1984    plannedMember   48.941530   8.405472
2   1983    storeMember 49.999355   8.711121
3   1982    mobilePlannedMember 51.838272   6.614867
4   1981    plannedMember   52.841810   7.519561
... ... ... ... ...
631 850 storeNoMember   50.713607   7.044930
632 849 storeNoMember   51.486631   7.214458
633 847 storeMember 49.898628   10.896140
634 846 storeMember 49.840614   7.861260
635 845 storeNoMember   52.201666   8.788376
636 rows × 4 columns

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM