不久前我为自己构建了这个小RSS阅读器,我很高兴能更新它,将垃圾从描述标签中排除。我现在正忙着测试它,以便从描述标签中删除&;lt;(所有内容)&;gt;,我很难得到这个文件。你知道吗
到目前为止,我的代码是这样的
from re import findall
from Tkinter import *
from urllib import urlopen
disc = []
URL = 'http://feeds.sciencedaily.com/sciencedaily/matter_energy/engineering?format=xml'
O_W = urlopen(URL).read()
disc_ex = findall('<description>(.*)</description>',O_W)
for i in disc_ex:
new_disc = i.replace(findall('<(.*)>',i),'')
disc.extend([new_disc])
所以在我尝试删除一些垃圾文本的新代码行之前,我通常会让我的文本像这样通过
"Tailored DNA structures could find targeted cells and release their molecular payload selectively into the cells.<img src="http://feeds.feedburner.com/~r/sciencedaily/matter_energy/engineering/~4/J1bTggGxFOY" height="1" width="1" alt=""/>"
我想要的只是没有垃圾的文本,所以本质上只是:
"Tailored DNA structures could find targeted cells and release their molecular payload selectively into the cells."
有什么建议吗?你知道吗
有几种解决方案,例如BeautifulSoup。要遵循您的想法,请避免使用“<;”…“>;”括号中的字符串,只需更改最后一行:
相关问题 更多 >
编程相关推荐