【问题标题】:Python Web Scraping Product PricePython网页抓取产品价格
【发布时间】:2021-03-22 09:20:02
【问题描述】:

我正在尝试在此网站上抓取产品价格:https://www.webhallen.com/se/product/232445-Logitech-C920-HD-Pro-Webcam

我尝试过使用

price = str(soup.find('div', {"class": "add-product-to-cart"}))

price = soup.find(id="add-product-to-cart").get_text()

但不幸的是,我没有运气。该项目不返回任何价格。价格/文本存储在跨度类中。

【问题讨论】:

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


    【解决方案1】:

    整个网站都在JavaScript 后面,因此您不会使用bs4 获取任何内容。但是,有一个 API 端点包含您需要的所有数据。

    获取方法如下:

    import requests
    
    with requests.Session() as session:
        response = session.get("https://www.webhallen.com/api/product/232445").json()
        print(response["product"]["price"]["price"])
    

    输出:

    1190.00
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-04
    • 2017-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    相关资源
    最近更新 更多