既然能够用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. [转]MySQL主从复制入门

    1.MySQL主从复制入门 首先,我们看一个图: 影响MySQL-A数据库的操作,在数据库执行后,都会写入本地的日志系统A中. 假设,实时的将变化了的日志系统中的数据库事件操作,在MYSQL-A的33 ...

  2. sharepoint2013隐藏左侧导航栏更换新的

    $("#zz16_V4QuickLaunchMenu").hide()//隐藏 更换新的 <script type="text/javascript" s ...

  3. action 方法的访问

    Action中的方法的访问: 访问Action的中的方法,默认情况下只能访问execute方法.那么多次请求就不能提交到一个Action.能不能一个模块的多次请求提交到一个Action中? * 需要使 ...

  4. 关闭window 8.1 的skydrive

    gpedit.msc-->计算机配置-->管理模板-->windows组件 -->skydrive-->阻止使用skydrive执行文件存储

  5. 针对Xcode的警告忽略消除处理

    一.问题描述 html代码如下 <html> <head> <meta charset="utf-8"/> <title>我的网页& ...

  6. javax.transaction.xa.XAException: java.sql.SQLException: 无法创建 XA 控制连接。错误: 未能找到存储过程 'master..xp_sqljdbc_xa_init'

    配置JTA SQL Server XADataSource参考:https://msdn.microsoft.com/zh-cn/library/aa342335.aspx 使用 JDBC 驱动程序 ...

  7. BestCoder22 1002.NPY and arithmetic progression(hdu 5143) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5143 题目意思:给出 1, 2, 3, 4 的数量,分别为a1, a2, a3, a4,问是否在每个数 ...

  8. 【QT】C++ GUI Qt4 学习笔记2

    Go To Cell 利用QT Desinger做好界面后加入的代码有 gotocelldialog.h #ifndef GOTOCELLDIALOG_H #define GOTOCELLDIALOG ...

  9. 【XLL API 函数】xlSet

    快速的将常数值放入到单元格区域中. 原型 Excel12(xlSet, LPXLOPER12 pxRes, 2, LPXLOPER12 pxReference,LPXLOPER pxValue); 参 ...

  10. September 2nd 2016 Week 36th Friday

    How does the world look through your eyes? 你眼里的世界是什么样子的? How does the world look through your eyes? ...