1 に答える
3
次のコードでは:
foundPrice = soup.findAll('span', {'itemprop':'price'})
if found is not None:
の結果をfindAll
tofoundPrice
に代入しましたが、if
文は comparefound
です。
以下を試してください:
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'
于 2013-09-13T08:26:04.573 に答える