BeautifulSoup 错误的开始标签?
我正在尝试把Wordpress的XML文件转换成Octopress格式,部分使用BeautifulSoup这个工具来进行迁移。
当我运行exitwp这个命令时,输出结果是这样的:
writing......................................................Traceback (most recent call last):
File "exitwp.py", line 293, in <module>
write_jekyll(data, target_format)
File "exitwp.py", line 284, in write_jekyll
out.write(html2fmt(i['body'], target_format))
File "exitwp.py", line 45, in html2fmt
return html2text(html, '')
File "/Users/kevinquillen/Documents/workspace/exitwp2/html2text.py", line 700, in html2text
return optwrap(html2text_file(html, None, baseurl))
File "/Users/kevinquillen/Documents/workspace/exitwp2/html2text.py", line 695, in html2text_file
h.feed(html)
File "/Users/kevinquillen/Documents/workspace/exitwp2/html2text.py", line 285, in feed
HTMLParser.HTMLParser.feed(self, data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/HTMLParser.py", line 108, in feed
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/HTMLParser.py", line 148, in goahead
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/HTMLParser.py", line 229, in parse_starttag
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/HTMLParser.py", line 304, in check_for_whole_start_tag
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/HTMLParser.py", line 115, in error
HTMLParser.HTMLParseError: malformed start tag, at line 1, column 64
我试过使用BeautifulSoup的版本3.2.0和3.0.7a,但都没有什么效果。
我还尝试过导出不同时间范围的帖子,但仍然在第1行出现同样的错误,只是列号在变化。
我能想到的唯一原因是一些旧帖子里有广告代码,但除此之外,我该如何轻松找到是哪个帖子内容导致了这个问题呢?
我在OSX 10.7上使用的是Python 2.7。
补充:在一个页面导出(只有2个页面)时也出现了这个问题,而这些页面没有任何错误的标记。
更新:看起来它不喜欢锚标签。像下面这样的标签,内容里很基本的链接。去掉这些标签后,它就能正确编译了。为什么它不喜欢这种HTML呢?去掉这些标签后就没有错误了。
<a href="http://www.google.com" target="_blank">Google</a>
1 个回答
1
把你的代码改成这样(在 html2text.py 文件里):
try:
HTMLParser.HTMLParser.feed(self, data)
except:
print 'malformed data: %r' % data
raise
我想你会发现,'data' 里面有些奇怪的东西。如果没有,请把这些数据加到你的问题里。