【问题标题】:Failed to scrape price related information from a site using requests无法使用请求从网站上抓取价格相关信息
【发布时间】:2021-05-30 02:22:37
【问题描述】:

我正在尝试使用 requests 模块从 webpage 中抓取产品的 product titledescriptionprice。尽管该页面的内容是动态的,但大多数产品信息都可以在页面源中的某些脚本标记中获得。

我已经从该页面抓取了product titledescription,它们位于容器变量中。不幸的是,我在集装箱内找不到价格。因此,我希望使用 requests 模块从该站点刮取 Regular price: $8.97Sale price: $5.97

import re
import json
import requests
from pprint import pprint

url = "https://www.walmart.ca/en/ip/terra-delyssa-tunisian-extra-virgin-olive-oil/6000196167258"
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36'
}
res = requests.get(url,headers=headers)
items = re.findall(r"window.__PRELOADED_STATE__=(.*?);<",res.text)[0]
container = json.loads(items)['entities']['skus']
for i in container:
    product_name = container[i]['name']
    description = container[i]['longDescription']
    print(product_name,description)

如何使用请求从该网站上抓取价格信息?

【问题讨论】:

    标签: python python-3.x web-scraping python-requests


    【解决方案1】:

    你有 242 声望,所以我不能

    无论如何https://www.walmart.ca/api/product-page/v2/price-offer发送post请求到这个链接你会得到你的东西

    只需使用硒

    【讨论】:

    • 是的,你是对的。我想知道我怎么错过了!!非常感谢您的指点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 2021-06-22
    • 2018-06-30
    相关资源
    最近更新 更多