【发布时间】:2011-11-19 21:41:57
【问题描述】:
我对 python 很陌生。很新。我从教程中复制了以下内容
#!/usr/bin/python
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"
我得到错误:
Traceback (most recent call last):
File "test.py", line 8, in <module>
patFinderTitle = re.compile('<title>(.*)</title>')
NameError: name 're' is not defined
我做错了什么?
【问题讨论】:
-
您是从哪个教程中复制的?它充满了错误。
-
那么您应该将您的代码与此处的随附代码进行比较:newthinktank.com/2010/11/…。经过一番整理,我发现它有效。
-
我回滚了您对该问题的编辑,因为不接受变色龙问题。你不能只是让那些发布你原来问题的答案的人的努力付诸东流。
标签: python