【发布时间】:2019-06-09 17:15:52
【问题描述】:
我正在构建网络爬虫网站,但在提取亚马逊产品价格时遇到问题。
注意:此 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