import feedparser
feed = feedparser.parse('http://mcupdate.tumblr.com/rss')
item_titles = [item['title'] for item in feed['items']] # get the items titles
minecraft_versions = [title for title in item_titles if re.match('^Minecraft [0-9\.]+$',title)] # keep the titles that matches the regex
latest_version = minecraft_versions[0][10:] # get the latest version
此代码段将执行以下几个简单步骤:
1)从此站点检索RSS源mcupdate.tumblr.com 2) 查找“Minecraft”的RegExp,它比“\”多一个数字,比“than one digit than”多一个数字。或者只是minecraft和2(“\”+数字)。 3) 而不是只选择最后一个结果(推荐) 4) 再次寻找那些数字(这次没有雷击机)。你知道吗
如果您只使用第一个命令(最多使用第一个“|”),并查看下载的文件以获得实际解析内容的“感觉”,那就更好了。你知道吗
所有这些都应该可以通过标准的Python库来实现。你知道吗
尝试查看urllib2文档来获取RSS提要。您还可以查看RSS libraries来解析它。你不需要使用grep,你需要一个版本号。你知道吗
相关问题 更多 >
编程相关推荐