对不起,我没有合适的词来称呼你。我要做的是这个代码通过给我所有的文本来满足我的要求。但问题是,在获取文本时,会出现诸如“<;p>;”、“<;a href….>;”、“<;h1>;”、“<;h2>;”之类的情况。。。。也在印刷。有人能帮我跳过那些标签吗? 我的代码:(我使用的是python2.7.8)
import urllib
from xml.etree.ElementTree import parse
# Download the RSS feed and parse it
u = urllib.urlopen('http://planet.python.org/rss20.xml')
doc = parse(u)
# Extract and output tags of interest
for item in doc.iterfind('channel/item'):
# title = item.findtext('title')
# date = item.findtext('pubDate')
# link = item.findtext('link')
des = item.findtext('description')
# print(title)
# print(date)
# print(link)
print(des)
print()
尝试使用BeautifulSoup解析HTML内容 如果你只需要文本的话,这样的东西就行了。如果需要HTML内容中的特定信息,可以解析HTML。你知道吗
相关问题 更多 >
编程相关推荐