我正在关注这些教程http://importpython.blogspot.com/2009/12/how-to-get-beautifulsoup-to-filter.html和http://importpython.blogspot.com/2009/12/how-to-screen-scrape-craigslist-using.html甚至复制粘贴的代码我似乎无法获得打印链接的标题,因为我得到一个列表索引超出范围分别是第11行和第8行。如果我复制代码,我做错了什么。我试过其他变化,如只返回链接和运作完全正常,所以我不认为这是一个地方问题Beautifulsoup内容返回列表索引超出范围
编辑
的问题是下面的代码(从http://importpython.blogspot.com/2009/12/how-to-screen-scrape-craigslist-using.html):
from BeautifulSoup import BeautifulSoup #1
from urllib2 import urlopen #2
site = "http://sfbay.craigslist.org/rea/" #3
html = urlopen(site) #4
soup = BeautifulSoup(html) #5
postings = soup('p') #6
for post in postings: #7
print post('a')[0].contents[0] #8
print post('a')[0]['href'] #9
给出了错误:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
IndexError: list index out of range
请包括一个[最小示例](http://sscce.org)代码,在您的实际问题中演示问题,而不仅仅是场外链接。 – jonrsharpe