第一次使用HTMLParser模块。试图在输出上使用标准字符串格式,但它给我一个错误。下面的代码:Python 2.7,处理HTMLParser时的ValueError
import urllib2
from HTMLParser import HTMLParser
class LinksParser(HTMLParser):
def __init__(self, url):
HTMLParser.__init__(self)
req = urllib2.urlopen(url)
self.feed(req.read())
def handle_starttag(self, tag, attrs):
if tag != 'a': return
for name, value in attrs:
print("Found Link --> {]".format(value))
if __name__ == "__main__":
LinksParser("http://www.facebook.com"
产生以下错误:
File "C:\Users\workspace\test\src\test.py", line 15, in handle_starttag
print("Found Link --> {]".format(value))
ValueError: unmatched '{' in format
哇,我觉得很傻。很好的吸引眼球。大声笑,也许我应该增加我的编辑器的字体大小。 :)现在工作正常。 – Stev0 2010-09-01 14:44:18