我正在尝试使用python抓取购物者的商品信息。
因为它使用的是ajax,所以我尝试从以下位置提取它:https://shopee.com.my/api/v2/item/get?itemid=5859069631&shopid=206039726
当我在浏览器中复制上面的链接时,它可以很好地处理我需要的所有信息。但是当我尝试使用request.get()获取它时,它会响应一个没有实际数据的json;
{'item': None, 'version': 'be8962b139db1273b88c291407137744', 'data': None, 'error_msg': None, 'error': None}
我的代码:
url = 'https://shopee.com.my/api/v2/item/get?itemid=5859069631&shopid=206039726'
response = requests.get(url)
if response.status_code == 200:
item_info = response.json()
print(item_info)奇怪的是,当我试图提取商店信息时,代码可以很好地使用: url = 'https://shopee.com.my/api/v4/product/get_shop_info?shopid=206039726‘。
不确定原因以及我应该如何解决这个问题。非常感谢!!
发布于 2021-06-07 02:27:30
添加User-Agent HTTP header,获取正确结果:
import json
import requests
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"
}
url = "https://shopee.com.my/api/v2/item/get?itemid=5859069631&shopid=206039726"
response = requests.get(url, headers=headers)
if response.status_code == 200:
item_info = response.json()
print(json.dumps(item_info, indent=4))打印:
{
"item": {
"itemid": 5859069631,
"price_max_before_discount": -1,
"item_status": "n",
"can_use_wholesale": false,
"brand_id": null,
"show_free_shipping": true,
"estimated_days": 6,
"is_hot_sales": false,
"is_slash_price_item": false,
"upcoming_flash_sale": null,
"slash_lowest_price": null,
"is_partial_fulfilled": false,
"condition": 2,
"show_original_guarantee": true,
"add_on_deal_info": null,
"is_non_cc_installment_payment_eligible": false,
"categories": [
{
"display_name": "Computer & Access",
"catid": 340,
"image": null,
"no_sub": true,
"is_default_subcat": true,
"block_buyer_platform": null
},
{
"display_name": "Des",
"catid": 17578,
"image": null,
"no_sub": false,
"is_default_subcat": true,
"block_buyer_platform": null
},
{
"display_name": "All-in-one Des",
"catid": 20050,
...https://stackoverflow.com/questions/67862346
复制相似问题