私は非常にPythonに慣れています。非常に新しい。NameError:名前 're'が定義されていません
Traceback (most recent call last):
File "test.py", line 8, in <module>
patFinderTitle = re.compile('<title>(.*)</title>')
NameError: name 're' is not defined
は私が間違って何をやっている:私は、私はエラーを取得するチュートリアルから
#!/usr/bin/python
import re
from urllib import urlopen
from BeautifulSoup import BeautifulSoup
webpage = urlopen('http://feeds.huffingtonpost.com/huffingtonpost/LatestNews').read
patFinderTitle = re.compile('<title>(.*)</title>')
patFinderLink = re.compile('<link rel.*href="(.*)"/>')
findPatTitle = re.findall(patFinderTitle,webpage)
findPatLink = re.findall(patFinderLink,webpage)
listIterator = []
listIterator[:] = range(2,16)
for i in listIterator:
print findPatTitle[i]
print findPatLink[i]
print "\n"
を以下にコピーしましたか?
編集:私はimport re
を追加しましたが、現在は次を得る:
File "/scripts/_prod/test.py", line 13, in <module>
findPatTitle = re.findall(patFinderTitle,webpage)
File "/usr/lib64/python2.6/re.py", line 177, in findall
return _compile(pattern, flags).findall(string)
TypeError: expected string or buffer
このチュートリアルをコピーしましたか?それはエラーで散在しています。 – Johnsyweb
http://www.youtube.com/watch?v=Ap_DlSrT-iE&feature=related –
次にコードを以下のコードと比較してください:http://www.newthinktank.com/2010/11/python-2 -7-tutorial-pt-13-website-scraping /。ちょっと整理した後、私はそれが動作することがわかった。ありがとう。 – Johnsyweb