1
4

1 回答 1

3

在以下代码中:

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

您将结果分配给findAllto foundPrice,但if语句 compare 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'
于 2013-09-13T08:26:04.573 回答