此代码将提取所有亚马逊链接。但是页面上有1个链接(可能不止一个)未显示在结果中。
myurl='http://www.apartmenttherapy.com/11-everyday-items-under-25-everyone-needs-at-home-223494?utm_source=RSS&utm_medium=feed&utm_campaign=Category%2FChannel%3A+Main'
import urllib2
import BeautifulSoup
request = urllib2.Request(myurl)
response = urllib2.urlopen(request)
soup = BeautifulSoup.BeautifulSoup(response)
for a in soup.findAll('a'):
if 'amazon' in a['href']:
print a['href']
如何确保显示所有亚马逊链接?