我想从这个页面获得价格
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"
答案 0 :(得分:3)
在以下代码中:
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'