既然能够用python解析rss,那么也顺带研究下生成rss。

其实很简单,只是生成一个比较特殊点的xml文档而已。

这里我使用了PyRss2Gen,用法很简单,看代码就知道了,如下:

 import datetime
import PyRSS2Gen rss = PyRSS2Gen.RSS2(
title = "Andrew's PyRSS2Gen feed",
link = "http://www.dalkescientific.com/Python/PyRSS2Gen.html",
description = "The latest news about PyRSS2Gen, a "
"Python library for generating RSS2 feeds", lastBuildDate = datetime.datetime.now(), items = [
PyRSS2Gen.RSSItem(
title = "PyRSS2Gen-0.0 released",
link = "http://www.dalkescientific.com/news/030906-PyRSS2Gen.html",
description = "Dalke Scientific today announced PyRSS2Gen-0.0, "
"a library for generating RSS feeds for Python. ",
guid = PyRSS2Gen.Guid("http://www.dalkescientific.com/news/"
"030906-PyRSS2Gen.html"),
pubDate = datetime.datetime(2003, 9, 6, 21, 31)),
PyRSS2Gen.RSSItem(
title = "Thoughts on RSS feeds for bioinformatics",
link = "http://www.dalkescientific.com/writings/diary/"
"archive/2003/09/06/RSS.html",
description = "One of the reasons I wrote PyRSS2Gen was to "
"experiment with RSS for data collection in "
"bioinformatics. Last year I came across...",
guid = PyRSS2Gen.Guid("http://www.dalkescientific.com/writings/"
"diary/archive/2003/09/06/RSS.html"),
pubDate = datetime.datetime(2003, 9, 6, 21, 49)),
]) rss.write_xml(open("pyrss2gen.xml", "w"))

这个生成的rss文档是这样的:

 <?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
<title>Andrew's PyRSS2Gen feed</title>
<link>http://www.dalkescientific.com/Python/PyRSS2Gen.html</link>
<description>The latest news about PyRSS2Gen, a Python library for generating RSS2 feeds</description>
<lastBuildDate>Thu, 15 May 2014 20:24:12 GMT</lastBuildDate>
<generator>PyRSS2Gen-1.1.0</generator>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<item>
<title>PyRSS2Gen-0.0 released</title>
<link>http://www.dalkescientific.com/news/030906-PyRSS2Gen.html</link>
<description>Dalke Scientific today announced PyRSS2Gen-0.0, a library for generating RSS feeds for Python. </description>
<guid isPermaLink="true">http://www.dalkescientific.com/news/030906-PyRSS2Gen.html</guid>
<pubDate>Sat, 06 Sep 2003 21:31:00 GMT</pubDate>
</item>
<item>
<title>Thoughts on RSS feeds for bioinformatics</title>
<link>http://www.dalkescientific.com/writings/diary/archive/2003/09/06/RSS.html</link>
<description>One of the reasons I wrote PyRSS2Gen was to experiment with RSS for data collection in bioinformatics. Last year I came across...</description>
<guid isPermaLink="true">http://www.dalkescientific.com/writings/diary/archive/2003/09/06/RSS.html</guid>
<pubDate>Sat, 06 Sep 2003 21:49:00 GMT</pubDate>
</item>
</channel>
</rss>

python生成RSS(PyRSS2Gen)的更多相关文章

  1. python 爬取喜马拉雅节目生成RSS Feed

    记录于:2020年12月03日用了N年的手机在经历N次掉落之后终于扛不住了,后背都张嘴了,估计再摔一次电池都能飞出来.换了手机,由于之前有听喜马拉雅的习惯,但是手机里自带有播客软件,强迫症逼着我不能下 ...

  2. JavaScript 解析 Django Python 生成的 datetime 数据 时区问题解决

    JavaScript 解析 Django/Python 生成的 datetime 数据 当Web后台使用Django时,后台生成的时间数据类型就是Python类型的. 项目需要将几个时间存储到数据库中 ...

  3. Asp.Net生成RSS方法

    一.RSS简介 什么是RSS? RSS是一种网页内容联合格式(web content sydication format). 它的名字是Really Simple Syndication的缩写. RS ...

  4. 【python】【转】Python生成随机数的方法

    如果你对在Python生成随机数与random模块中最常用的几个函数的关系与不懂之处,下面的文章就是对Python生成随机数与random模块中最常用的几个函数的关系,希望你会有所收获,以下就是这篇文 ...

  5. Python生成随机数的方法

    这篇文章主要介绍了Python生成随机数的方法,有需要的朋友可以参考一下 如果你对在Python生成随机数与random模块中最常用的几个函数的关系与不懂之处,下面的文章就是对Python生成随机数与 ...

  6. asp.net生成RSS

    经常看到博客.还有很多网站中有RSS订阅,今天就来玩玩asp.net生成RSS,在网上查找了相关资料 发现just soso,如下: aspx <?xml version="1.0&q ...

  7. Python 生成的页面中文乱码问题

    第一 保证 程序源文件里的中文的编码格式,如我们把 源文件的编码设置成utf8的. reload(sys) sys.setdefaultencoding('utf-8') 第二, 告诉浏览器,我们须要 ...

  8. 如何使用python生成xml

    最近要用python生成一个xml格式的文件.因为有一些内容是中文,原来的xml文件中使用了CDATA 的部分. 而之前的python程序所用的库中没有 创建这个区域的方法.无奈研究了大半天. 最后用 ...

  9. python生成随机图形验证码

    使用python生成随机图片验证码,需要使用pillow模块 1.安装pillow模块 pip install pillow 2.pillow模块的基本使用 1.创建图片 from PIL impor ...

随机推荐

  1. 善用VS中的Code Snippet来提高开发效率

    http://www.cnblogs.com/anderslly/archive/2009/02/16/vs2008-code-snippets.html http://www.cnblogs.com ...

  2. 【GoLang】GoLang UTF8 与 Unicode

    结论: 通用的UTF8编码可是Ken Thompson和Rob Pike共同发明的, 他们都是Go的作者. Go中rune对应unicode的码点, string只是UTF8编码.len(" ...

  3. 《oracle每天一练》Oracle冷备份与数据恢复

    相关帖子 转自http://blog.csdn.net/nsj820/article/details/5611361 备份 直接拷贝oracle目录下的admin.oradata(datafile,  ...

  4. 右下角浮窗&动画效果

    2015-07-17 11:07:57 CSS #goreg { width: 70px; position: fixed; bottom: 20px; right: 25px; ; opacity: ...

  5. Urllib2 总结

    Urllib2 总结 介绍 Urllib2是用于获取URLs(统一资源定位符)的一个Python模块.它以urlopen函数的形式提供了非常简单的接口.能够使用各种不同的协议来获取网址.它还提供一个稍 ...

  6. codeforces 557B. Pasha and Tea 解题报告

    题目链接:http://codeforces.com/problemset/problem/557/B 题目意思:有 2n 个茶杯,规定第 i 个茶杯最多只能装 ai 毫升的水.现在给出 w 毫升的水 ...

  7. 【编程题目】求1+2+…+n, 要求不能使用乘除法、for、while、if、else、switch、case和条件语句

    看到这个问题,第一个反应是真变态啊. 然后,直觉是不能用循环就只能用递归了.可递归怎么跳出来却遇到了麻烦, 我连goto语句都考虑了也没弄好. 后来想到一个非常NC的方法:查找表. 如果n限定一个比较 ...

  8. 20145213《Java程序设计》第二周学习总结

    20145213<Java程序设计>第二周学习总结 教材学习内容总结 本周娄老师给的任务是学习教材的第三章--基础语法.其实我觉得还蛮轻松的,因为在翻开厚重的书本,一股熟悉的气息扑面而来, ...

  9. IOS-frame和bounds有什么不同

    frame指的是:该view在父view坐标系统中的位置和大小.(参照点是父亲的坐标系统) 它的坐标原点是随着父View位置的改变而改变的 bounds指的是:该view在本身坐标系统中 的位置和大小 ...

  10. Java抽象类接口、内部类题库

    一.    选择题 1. Person类和Test类的代码如下所示,则代码中的错误语句是(  C  ).(选择一项)   public class Person { public String nam ...