2016-03-30 15 views
1

私は、urllib2を使ってHTMLを解析し、PyRSS2Genを利用してRSSフィードをXMLで作成するプログラムを作成しようとしています。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() 

答えて

0

私はちょうどそのようにファイルに書き留めました。

news = open("news.rss.xml", "w") 
news.write("<?xml version=\"1.0\" ?>") 
news.write("\n") 
news.write("<rss xmlns:atom=\"http://www.w3.org/2005/Atom\" version=\"2.0\">") 
news.write("\n") 
news.write("<channel>") 
news.write("\n") 

など

関連する問題