gpt4 book ai didi

python - 漂亮的汤获得标签或获得价格

转载 作者:行者123 更新时间:2023-11-30 23:33:27 24 4
gpt4 key购买 nike

我想从该页面获取价格

http://www.fastfurnishings.com/Aura-Floor-Lamp-p/lsi_ls-aurafl-gy-gn.htm

价格在

<font class="text colors_text"><b>Retail Price:<s></b> $199.00 </font><br /><b><FONT class="pricecolor colors_productprice"></s>Price: <span itemprop='price'>$139.00</span> </font></b>

我想要这个价格 139.00 美元

我有下面的代码,但没有找到价格

html = urllib2.urlopen(value)
soup = BS(html)
foundPrice = soup.findAll('span', {'itemprop':'price'})
if found is not None:
print "found a price"
else:
print" No Lunk"

最佳答案

在下面的代码中:

foundPrice = soup.findAll('span', {'itemprop':'price'})
if found is not None:

您将findAll的结果分配给foundPrice,但if语句比较found

尝试以下操作:

import urllib2

from bs4 import BeautifulSoup


url = 'http://www.fastfurnishings.com/Aura-Floor-Lamp-p/lsi_ls-aurafl-gy-gn.htm'
u = urllib2.urlopen(url)
try:
soup = BeautifulSoup(u)
finally:
u.close()

span = soup.find('span', {'itemprop':'price'})
if span is not None:
print span.string
else:
print 'Not found'

关于python - 漂亮的汤获得<s>标签或获得价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18781528/

24 4 0