如何使用python脚本访问XHR数据?

此URL中包含以下数据:

https://forsikringsguiden.dk/signalr/poll?transport=longPolling&messageId=d-3E730B44-EB%2C0%7CTX%2C1%7CTY%2C1%7CTZ%2C0&clientProtocol=1.4&connectionToken=81u0%2BTRKNqfgWWdC72ld4wHwbmFGpkCXZRiPe3a1mJPmKvrJpUhBiq3qOThYE04iotxtecRVERe7QA2OyL0GugQoS2nyzbnlcvGZpV1JSav5XqGY0OCrpBKVp0vqXToc&connectionData=%5B%7B%22name%22%3A%22insuranceofferrequesthub%22%7D%5D&tid=5&_=1572867896650

如何使用python脚本访问数据?

下面是标题信息。我相信使用这些数据的组合可以生成URL,但是我认为将所有不同的信息合并为最终URL是有风险的。

让我知道是否缺少其他信息,我不知道我的问题中还需要什么。

我需要的数据是“ companydisplayname”,“ basicprice”和“ discountprice”。

下面的图像来自主URL的检查,这要求您在添加信息之前填写一些表格。它比较了保险价格:

https://forsikringsguiden.dk/#!/bilforsikring/resultatside

如何使用python脚本访问XHR数据?

mz1bw6l16 回答:如何使用python脚本访问XHR数据?

您可以使用以下脚本。 首先,我们可以使用 requests 来获取JSON,然后对其执行操作以获取所需的结果:

Root

输出:

import requests
request_data = requests.get(url ="https://forsikringsguiden.dk/signalr/poll?transport=longPolling&messageId=d-3E730B44-EB%2C0%7CTX%2C1%7CTY%2C1%7CTZ%2C0&clientProtocol=1.4&connectionToken=81u0%2BTRKNqfgWWdC72ld4wHwbmFGpkCXZRiPe3a1mJPmKvrJpUhBiq3qOThYE04iotxtecRVERe7QA2OyL0GugQoS2nyzbnlcvGZpV1JSav5XqGY0OCrpBKVp0vqXToc&connectionData=%5B%7B%22name%22%3A%22insuranceofferrequesthub%22%7D%5D&tid=5&_=1572867896650")
request_json = request_data.json()

# Now Perform Operations
for a_key in data["M"]:
    for a_value in a_key["A"]:
        # Checking whether companydisplayname,basicprice and discounted price exists or not
        if "offers" in a_value and "companydisplayname" in a_value["offers"][0] and "basicprice" in a_value and "discountedprice" in a_value:
            print "Company Name : ",a_value["offers"][0]["companydisplayname"]
            print "Basic Price : ",a_value["basicprice"]
            print "Discounted Price : ",a_value["discountedprice"]

希望这会帮助您!

本文链接:https://www.f2er.com/3166785.html

大家都在问