首页 > 解决方案 > 没有从python中的请求中获取数据

问题描述

我试图从在线商店获取产品信息。它不需要任何类型的身份验证。我可以从浏览器中看到产品信息。我在开发人员工具中进行了检查,发现了从URL获取数据的请求。我的python代码如下

import requests

def coles():
    URL = "https://shop.coles.com.au/search/resources/store/20520/productview/bySeoUrlKeyword/mutti-tomato-passata-2349503p"
    PARAMS = {
        "catalogId": 12064
    }
    res = requests.get(URL,PARAMS)
    print(res.text)


#coles()
if __name__ == '__main__':
    coles()

但我得到的是这个而不是产品信息

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="about:blank">
</head>
<body>
<script src="/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/j.js"></script>
<script src="/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/f.js"></script>
<script src="/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/fingerprint/script/kpf.js?url=/149e9513-01fa-4fb0-aad4-566afd725d1b/2d206a39-8ed7-437e-a3be-862e0f06eea3/fingerprint&token=dcc221cb-d87a-e9e3-5316-7c7a20910bf8"></script>
</body>
</html>

但是在检查中,我得到了这样的东西。也许我需要添加一些标题信息或遗漏一些东西。 在此处输入图像描述

这是请求信息和参数 ython

如果我将此请求 URL放在浏览器中,我会得到数据。

标签: pythonrestweb-scrapingpython-requests

解决方案


推荐阅读