我正在尝试编写一个程序,该程序利用urllib2来解析HTML,然后利用PyRSS2Gen创建XML中的RSS源。Python - 用PyRSS2Gen生成RSS
我一直在试图运行它得到的错误
Traceback (most recent call last): File "pythonproject.py", line 46, in get_rss() File "pythonproject.py", line 43, in get_rss rss.write_xml(open("cssnews.rss.xml", "w")) File "build/lib/PyRSS2Gen.py", line 34, in write_xml self.publish(handler) File "build/lib/PyRSS2Gen.py", line 380, in publish item.publish(handler) File "build/lib/PyRSS2Gen.py", line 427, in publish _opt_element(handler, "title", self.title) File "build/lib/PyRSS2Gen.py", line 58, in _opt_element _element(handler, name, obj) File "build/lib/PyRSS2Gen.py", line 53, in _element obj.publish(handler) AttributeError: 'builtin_function_or_method' object has no attribute 'publish'
。
从我能找到的其他用户在尝试为XML创建新标记时遇到此问题,但我试图使用PyRSS2Gen给出的默认标记。检查PyRSS2Gen.py文件显示我正在使用的write_xml()命令,以及如何通过从列表中弹出它们将值分配给rss项目的错误?
def get_rss():
sys.path.append('build/lib')
from PyRSS2Gen import RSS2, RSSItem
rss = RSS2(
title = 'Python RSS Creator',
link = 'technews.acm.org',
description = 'Creates RSS out of HTML',
items = [],
)
for x in range(0, len(rssTitles)):
rss.items.append(RSSItem(
title = rssTitles.pop,
link = rssLinks.pop,
description = rssDesc.pop,
))
rss.write_xml(open("cssnews.rss.xml", "w"))
# 5 - Call function
get_rss()