python - 将查询字符串参数传递给请求调用不起作用
问题描述
我正在尝试使用此 python 脚本获取此 [产品 url][1] 的 json 响应。我查看了站点查询参数并从开发工具中添加了网络选项卡。
我使用了类似的方法 [here][2] 来获取查询的 json 响应,但是当我尝试使用下面的代码时,它产生了错误。这是代码:
def getIndividualItemData():
print("fetching ")
api_url = 'https://www.walmart.com/product/electrode/api/wpa'
params = {
'el': 'sponsored-container-middle-2',
'type': 'product',
'min': '3',
'max': '15',
'placementId': '480x345_B-C-OG_TI_2-15_HL-BOTTOM-NY',
'platform': 'mobile',
'bucketId':"",
'bnd': 'Omid Scobie',
'moduleLocation': 'bottom',
'zipCode': '19146',
'isZipLocated': 'true',
'sMode': '0',
'pageType': 'item',
'vtc': 'QrqzIuiG6-yciq_CD4uAJg',
'uid': 'daa00990-dab1-4257-9705-3d4a31be8aee',
'rviItems': '915257222',
'itemsAddedToCart': '0',
'viewportHeight': '616',
'viewportWidth': '150',
'userLoggedIn': 'false',
'showBrand': 'false',
'itemsList':"" ,
'pageId': '915257222',
'keyword': 'Finding Freedom Harry and Meghan and the Making of a Modern Royal Family Hardcover',
'taxonomy': '3920_5196470_2244664',
'persistControls': 'true',
'isTwoDayDeliveryTextEnabled': 'true',
'mloc': 'bottom',
'module': 'wpa'
}
try:
try:
data = requests.get(api_url, params=params).json()
except Exception as e:
print(e)
except Exception as e:
print(e)
我不断打印出这个错误
期望值:第 1 行第 1 列(字符 0)
是什么导致了错误,如何获取产品 json 响应?
我尝试了 .text 打印,它只显示很少的数据 [1]:https ://www.walmart.com/ip/2-Pack-Maxwell-House-Original-Roast-Medium-Ground-Coffee-Caffeinated -42-5-oz-Canister/915257222 [2]:Python:如何为 Python 请求设置参数
解决方案
推荐阅读
- node.js - 我可以删除旧版本的节点吗?
- php - php有没有办法跟踪数据库关系
- progressive-web-apps - PWA 无法离线正常工作。Uncaught (in promise) TypeError: Failed to fetch
- c# - 我应该将事务与命令 ExecuteNonQuery 一起使用吗?
- scala - 如何计算 Spark 数据框中的每小时计数(按时间戳类型分组)?
- android - 如何从我的 Android 设备访问我的本地主机
- javascript - MongoDB 函数未按预期返回
- linux - 如何处理 http 客户端的最大连接数问题?
- java - 在 android - java 中使用 mbtiles 文件或 sqlitedb 文件制作地图
- asp.net-mvc - 如何在 ADFS 2018 中配置注销后重定向 uri?