【问题标题】:how to get the price value after selecting the the product size in amazon using python?使用python在亚马逊选择产品尺寸后如何获取价格值?
【发布时间】:2019-06-09 17:15:52
【问题描述】:

我正在构建网络爬虫网站,但在提取亚马逊产品价格时遇到问题。

这里是网址:https://www.amazon.com/Viishow-Printed-Dresses-Pockets-Wine/dp/B07PNGB9H3/ref=sr_1_3?_encoding=UTF8&qid=1560098637&s=fashion-womens-intl-ship&sr=1-3&th=1

注意:此 URL 未选择尺寸,有两个价格,例如:16.99 美元 - 22.99 美元

当我选择尺码时,它会给我选择尺码的产品的确切价格,但是当我使用 python 抓取它时,它给我的是范围价格(16.99 美元 - 22.99 美元)而不是 22.99 美元

import requests
from bs4 import BeautifulSoup

URL = "https://www.amazon.com/Viishow-Printed-Dresses-Pockets-Wine/dp/B07PMHY51F/ref=sr_1_3?_encoding=UTF8&qid=1560098637&s=fashion-womens-intl-ship&sr=1-3&th=1&psc=1"
# This URL with selected size with the product price ex: $22.99 but when I run the program it gives me two prices: $16.99 - $22.99 not this price: $22.99

res = requests.get(URL)
soup = BeautifulSoup(res.text, "html.parser")
price = soup.find(id="priceblock_ourprice").get_text()

print(price)

现在它应该提取输出价格 = $22.99 但它提取输出价格 = $16.99 - $22.99

你能帮我解决这个问题吗?

【问题讨论】:

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


    【解决方案1】:

    我需要更改解析器并使用不同的 id

    import requests
    from bs4 import BeautifulSoup
    
    URL = "https://www.amazon.com/Viishow-Printed-Dresses-Pockets-Wine/dp/B07PMHY51F/ref=sr_1_3?_encoding=UTF8&qid=1560098637&s=fashion-womens-intl-ship&sr=1-3&th=1&psc=1"
    # This URL with selected size with the product price ex: $22.99 but when I run the program it gives me two prices: $16.99 - $22.99 not this price: $22.99
    
    res = requests.get(URL, headers = {'User-Agent' : 'Mozilla/5.0'})
    soup = BeautifulSoup(res.text, "lxml")
    price = soup.select_one('#priceblock_ourprice').text
    print(price)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-10
      • 2015-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-01
      • 1970-01-01
      相关资源
      最近更新 更多