我仍然是一名python初学者。作为一个实践项目,我想编写我自己的RSS阅读器。 我在这里找到了一个有用的教程:learning python。我使用的教程中提供的代码:试图解析用python编写的RSS阅读器的提要
#! /usr/bin/env python
import urllib2
from xml.dom import minidom, Node
""" Get the XML """
url_info = urllib2.urlopen('http://rss.slashdot.org/Slashdot/slashdot')
if (url_info):
""" We have the RSS XML lets try to parse it up """
xmldoc = minidom.parse(url_info)
if (xmldoc):
"""We have the Doc, get the root node"""
rootNode = xmldoc.documentElement
""" Iterate the child nodes """
for node in rootNode.childNodes:
""" We only care about "item" entries"""
if (node.nodeName == "item"):
""" Now iterate through all of the <item>'s children """
for item_node in node.childNodes:
if (item_node.nodeName == "title"):
""" Loop through the title Text nodes to get
the actual title"""
title = ""
for text_node in item_node.childNodes:
if (text_node.nodeType == node.TEXT_NODE):
title += text_node.nodeValue
""" Now print the title if we have one """
if (len(title)>0):
print title
if (item_node.nodeName == "description"):
""" Loop through the description Text nodes to get
the actual description"""
description = ""
for text_node in item_node.childNodes:
if (text_node.nodeType == node.TEXT_NODE):
description += text_node.nodeValue
""" Now print the title if we have one.
Add a blank with \n so that it looks better """
if (len(description)>0):
print description + "\n"
else:
print "Error getting XML document!"
else:
print "Error! Getting URL"<code>
一切都按预期工作,我首先想到了解它的一切。但是,当我使用另一个RSS源(例如“http://www.spiegel.de/schlagzeilen/tops/index.rss”)时,我从Eclipse IDE获得了我的应用程序的“终止”错误。该错误消息,因为我不知道究竟在哪里和为什么应用程序终止。调试器没有什么帮助,因为它忽略了我的断点。那么,这是另一个问题。
有人知道我在做什么错?
你可以尝试做一个二进制搜索(通过注释代码)来隔离问题吗? –
我试过了。我刚刚知道编译器不是错误消息,但我缺乏知识。 – jacib