python - 使用Python request.get param 但它给了我错误的url

标签 python python-requests

我正在尝试使用 Python 请求库从 Steam 中删除一些数据。但首先我需要修改我的网址

例如,如果我想访问带标签的游戏​​

  • 二维 [id:3871]
  • 1980 年代 [id:7743]

https://store.steampowered.com/search?tags=7743%2C3871

这是我需要的链接。但是当我这样做时

steam_url = "https://store.steampowered.com/search?"
search = request.get(steam_url, params = {'tags' : [7743, 3871]})

我得到这个网址

https://store.steampowered.com/search?tags=7743&tags=3871

它只向我展示 2D 游戏 [id : 3871]

为了解决这个问题,我尝试这样做

steam_url = "https://store.steampowered.com/search?"
search = get(steam_url, params = {'tags' : '%2C'.join(list(map(str,[7743, 3871])))})

然后我得到这个网址

https://store.steampowered.com/search?tags=7743%252C3871

我不明白为什么这些 ID 之间有 %252C

我应该做什么?

最佳答案

I couldn't understand why there is %252C between those ids.

因为您使用的是 '%2C'.join,它会转义为 %252C,其中 %25 是百分号。使用 ','.join 并让 requests.get 进行转义。

关于python - 使用Python request.get param 但它给了我错误的url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52578774/

相关文章:

python - 在python中求小矩阵

python - 动态事件条件

python - NumericType 错误 - 转换为 float 进行计算?

python - 获取 LinkedIn 公司股票 Python

python - 如何使请求包在Python中的CONNECT命令中发送UserAgent?

python - Google Oauth Python 请求 : Method Not Allowed

Python:创建一个类来读取目录中的文件

python POST请求和空值

python - 如何在python脚本中发送post请求正文

python - 将 json 数据(未定义/困惑)转换为 DataFrame 的正确方法是什么?