我正試圖學習如何使用BeautifulSoup進行屏幕刮擦。TypeError:在網頁上使用re.findall文本時的預期字符串 - 爲什麼?
from urllib import urlopen
from BeautifulSoup import BeautifulSoup
import re
webpage = urlopen('http://feeds.feedburner.com/zenhabits').read()
patFinderTitle = re.compile('<h4 class="itemtitle"><a href=(.*)</a></h4>')
findPatTitle = re.findall(patFinderTitle,webpage)
listIterator = []
listIterator[:] = range(1, 5)
for i in listIterator:
print findPatTitle[i]
print("\n")
錯誤
Traceback (most recent call last):
File "//da-srv1/users/xxxxx/Desktop/fetcher", line 14, in <module>
print findPatTitle[i]
**IndexError: list index out of range**
'urlopen('http://feeds.feedburner.com/zenhabits').read'是方法的名稱。我懷疑你要找的是'urlopen('http://feeds.feedburner.com/zenhabits').read()'。 – inspectorG4dget 2011-05-16 20:49:19