【发布时间】:2019-06-05 02:17:10
【问题描述】:
我正在尝试使用 python 3 的漂亮汤从电子商务网站上刮下商品的价格。我还需要做什么才能从我的第一次拉取中提取价格?
我尝试过其他的代码组合,但对这种方法的理解不是很深。
import requests
from bs4 import BeautifulSoup
page = requests.get('https://www.walmart.com/ip/GoGreen-Power-6-Outlet-Surge-Protector-16103MS-2-5-cord-White/46097919')
soup = BeautifulSoup(page.text, 'html.parser')
price_hide = soup.find(class_='price-characteristic')
print(price_hide)
wprice = price_hide.find_all(content)
print(wprice)
第一个打印功能起作用
<span class="price-characteristic" content="3.98" itemprop="price">3</span>
第二个没那么多。
我希望打印 3.98 的内容价格
【问题讨论】:
-
price_hide['content']或price_hide.get('content')
标签: html python-3.x web-scraping beautifulsoup