既然能够用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. windows8 安装TortoiseSVN后的反应

    因为工作需要,昨天安装了TortoiseSVN 64位版,没有马上重启. 随后,IIS中打开页面后浏览器一片空白,没有网页,没有地址,什么都没有.这时还没想到可能是TortoiseSVN的问题.后来实 ...

  2. 6.SpringMVC注解启用

    SpringMVC注解可以帮助我们快速地注入 属性和参数 提高开发效率. 由于 有相当一部分人讨厌xml配置方式 注解可以覆盖 xml则不能 使用注解比xml规范化,因为很多注解都是java的规范的范 ...

  3. HTTP 错误 500.19- Internal Server Error 错误解决方法

    1.点击发布的文件夹,选择属性 2.选择安全,添加一个用户就可以了,设置为完全 --今天公司网页打开出现Server Error in '/' Application.怎么样解决. 解决方法:控制面板 ...

  4. HDU 4870 Rating(概率、期望、推公式) && ZOJ 3415 Zhou Yu

    其实zoj 3415不是应该叫Yu Zhou吗...碰到ZOJ 3415之后用了第二个参考网址的方法去求通项,然后这次碰到4870不会搞.参考了chanme的,然后重新把周瑜跟排名都反复推导(不是推倒 ...

  5. C++与C#对比学习:类初始化

    类和柏拉图的理念世界 我们知道面向对象编程中到处是一个个的类,但类只是个概念性的东西,不是个实体,不占内存,你没实例化之前也不能用它.只有把类实例化成一个对象后,它才是一个真正存在的实体.占有内存,能 ...

  6. 【leetcode】Binary Tree Right Side View(middle)

    Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...

  7. 创建odoo数据库时出现错误原因

    安装完odoo 8.0后创建数据库时出现如下错误信息: Odoo Odoo Server Error Traceback (most recent call last): File "D:\ ...

  8. 118. Pascal's Triangle

    题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, ...

  9. 常用邮箱的服务器(SMTP/POP3)地址和端口总结

    163.com: POP3服务器地址:pop.163.com(端口:110) SMTP服务器地址:smtp.163.com(端口:25) 126邮箱: POP3服务器地址:pop.126.com(端口 ...

  10. SQL Server 查询时间段内数据

    方式一: ALTER Proc [dbo].[usp_Rpt_AcctTypeAudit] @FromDate datetime=null, -- yyyy-mm-dd (may change in ...