RSS
RSS 是用于分发 Web 站点上的内容的摘要的一种简单的 XML 格式。它能够用于共享各种各样的信息。关于RSS的详细信息在(http://www.rssboard.org/rss-profile ),这里面详细的讲了各种值的含义(虽然各个版本的支持不太一样,但是还是比较有通用性的)
RSS(Really Simple Syndication,简易信息聚合)是一种描述和同步网站内容的格式你可以认为是一种定制个性化推送信息的服务。它能够解决你漫无目的的浏览网页的问题。它不会过时,信息越是过剩,它的意义也越加彰显。网络中充斥着大量的信息垃圾,每天摄入了太多自己根本不关心的信息。让自己关注的信息主动来找自己,且这些信息都是用户自己所需要的,这就是RSS的意义。
我的博客RSS:https://blog.csdn.net/qq_34243930/rss/list
这里给出博客RSS的源码(部分):
<?xml version="1.0" encoding="utf-8" ?><?xml-stylesheet type="text/xsl" title="XSL Formatting" href="/static_files/rss/rss.xsl" media="all" ?>
<rss version="2.0">
<channel>
<title>Ssummer</title>
<image>
<link>https://blog.csdn.net/</link>
<url>https://csdnimg.cn/release/phoenix/static_blog/images/logo.gif</url>
</image>
<description>一个小可爱</description>
<link>https://blog.csdn.net/qq_34243930</link>
<language>zh-cn</language>
<generator>https://blog.csdn.net/</generator>
<ttl>5</ttl>
<copyright><![CDATA[Copyright © qq_34243930]]></copyright>
<pubDate>2019/02/08 23:54:44</pubDate>
<item>
<title><![CDATA[[原]图像处理-图片找不同Find the differences of the two images #Matlab下调用Python接口#SIFT算法应用]]></title>
<link>https://blog.csdn.net/qq_34243930/article/details/85316240</link>
<guid>https://blog.csdn.net/qq_34243930/article/details/85316240</guid>
<author>qq_34243930</author>
<pubDate>2018/12/28 00:36:22</pubDate>
<description>
<![CDATA[
说明
要求(含待处理图片等)、源代码见CSDN下载:
PPT展示、英文报告 见CSDN下载:
大作业要求
Task: Find the differences of the two images, ignoring butterfly
The code should be suitable for all image pairs.
找出经旋转或裁剪之后,像素点并不对应的两幅图片的不同之处。其中不... <div>
作者:qq_34243930 发表于 2018/12/28 00:36:22 <a href="https://blog.csdn.net/qq_34243930/article/details/85316240">原文链接</a> https://blog.csdn.net/qq_34243930/article/details/85316240 </div>
<div>
阅读:38 </div>
]]>
</description>
<category></category>
</item>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
1、generator:这个是生成这个订阅源的工具,也就是博客园自己提供的生成器
2、entry:每篇博文的块,所有的关于你某篇博客的内容都在这(有若干个块,为了不太长我只保留了一个)
3、content:这个里面貌似是可以加html的吗的,rss阅读器展示的就是这的内容
feedparser
feedparser 号称是一个 universal feed parser。
feedparser是一个Python的Feed解析库,可以处理RSS ,CDF,Atom 。使用它我们可从任何 RSS 或 Atom 订阅源得到标题、链接和文章的条目了。
一、feedparser的安装
1、下载feedparser安装包,解压文件夹到自己想放的地方。我使用的是5.2.1
https://pypi.org/project/feedparser/
已上传至CSDN:https://download.csdn.net/download/qq_34243930/10951032
2、修改setup.py文件
用python打开文件夹里面的setup.py文件,修改第一行代码,将from setuptools import setup改为from distutils.core import setup,然后保存。
3、cmd命令行打开,进入setup.py所在目录,执行命令:
python setup.py install
4、测试,关闭pycharm,再重新打开,命令行输入:import feedparser
不报错即为安装成功
这个大家常用的方法我并没有成功
报错如下:
找到了另一种方法:
如果用你用的是anaconde,方便了太多。
安装时在Anaconda Prompt 下输入:conda install feedparser
即可
此时使用import feedparser不会报错:
二、feedparser的使用
feedparser 最为核心的函数自然是 parse() 解析 URL 地址的函数feedparser.parse()
它返回的究竟是什么样的内容:
{'bozo': 1,
'bozo_exception': xml.sax._exceptions.SAXParseException('no element found'),
'encoding': 'utf-8',
'entries': [],
'feed': {},
'namespaces': {},
'version': ''}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
可以看到,得到是一个字典,’feed’(key) 对应的值(value)也是一个字典,’entries’ 则是 list。
截图放不下这里粘贴一个字典举例:
{'feed': {'title': 'Ssummer',
'title_detail': {'type': 'text/plain',
'language': None,
'base': 'https://blog.csdn.net/qq_34243930/rss/list',
'value': 'Ssummer'},
'image': {'links': [{'rel': 'alternate',
'type': 'text/html',
'href': 'https://blog.csdn.net/'}],
'link': 'https://blog.csdn.net/',
'href': 'https://csdnimg.cn/release/phoenix/static_blog/images/logo.gif'},
'subtitle': '一个小可爱',
'subtitle_detail': {'type': 'text/html',
'language': None,
'base': 'https://blog.csdn.net/qq_34243930/rss/list',
'value': '一个小可爱'},
'links': [{'rel': 'alternate',
'type': 'text/html',
'href': 'https://blog.csdn.net/qq_34243930'}],
'link': 'https://blog.csdn.net/qq_34243930',
'language': 'zh-cn',
'generator_detail': {'name': 'https://blog.csdn.net/'},
'generator': 'https://blog.csdn.net/',
'ttl': '5',
'rights': 'Copyright © qq_34243930',
'rights_detail': {'type': 'text/html',
'language': None,
'base': 'https://blog.csdn.net/qq_34243930/rss/list',
'value': 'Copyright © qq_34243930'},
'published': '2019/02/09 00:57:35',
'published_parsed': time.struct_time(tm_year=2019, tm_mon=2, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=4, tm_yday=32, tm_isdst=0)},
'entries': [{'title': '[原]图像处理-图片找不同Find the differences of the two images #Matlab下调用Python接口#SIFT算法应用',
'title_detail': {'type': 'text/plain',
'language': None,
'base': 'https://blog.csdn.net/qq_34243930/rss/list',
'value': '[原]图像处理-图片找不同Find the differences of the two images #Matlab下调用Python接口#SIFT算法应用'},
'links': [{'rel': 'alternate',
'type': 'text/html',
'href': 'https://blog.csdn.net/qq_34243930/article/details/85316240'}],
'link': 'https://blog.csdn.net/qq_34243930/article/details/85316240',
'id': 'https://blog.csdn.net/qq_34243930/article/details/85316240',
'guidislink': False,
'authors': [{'name': 'qq_34243930'}],
'author': 'qq_34243930',
'author_detail': {'name': 'qq_34243930'},
'published': '2018/12/28 00:36:22',
'published_parsed': time.struct_time(tm_year=2018, tm_mon=2, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=32, tm_isdst=0),
'summary': '说明\n要求(含待处理图片等)、源代码见CSDN下载:\nPPT展示、英文报告 见CSDN下载:\n大作业要求\n\nTask: Find the differences of the two images, ignoring butterfly\nThe code should be suitable for all image pairs.\n找出经旋转或裁剪之后,像素点并不对应的两幅图片的不同之处。其中不... <div>\n 作者:qq_34243930 发表于 2018/12/28 00:36:22 <a href="https://blog.csdn.net/qq_34243930/article/details/85316240">原文链接</a> https://blog.csdn.net/qq_34243930/article/details/85316240 </div>\n <div>\n 阅读:38 </div>',
'summary_detail': {'type': 'text/html',
'language': None,
'base': 'https://blog.csdn.net/qq_34243930/rss/list',
'value': '说明\n要求(含待处理图片等)、源代码见CSDN下载:\nPPT展示、英文报告 见CSDN下载:\n大作业要求\n\nTask: Find the differences of the two images, ignoring butterfly\nThe code should be suitable for all image pairs.\n找出经旋转或裁剪之后,像素点并不对应的两幅图片的不同之处。其中不... <div>\n 作者:qq_34243930 发表于 2018/12/28 00:36:22 <a href="https://blog.csdn.net/qq_34243930/article/details/85316240">原文链接</a> https://blog.csdn.net/qq_34243930/article/details/85316240 </div>\n <div>\n 阅读:38 </div>'},
'tags': []},
# 这里还有很多个feed{title:....},{},{},
'bozo': 0,
'headers': {'Server': 'openresty',
'Date': 'Fri, 08 Feb 2019 16:57:35 GMT',
'Content-Type': 'text/xml; charset=UTF-8',
'Transfer-Encoding': 'chunked',
'Connection': 'close',
'Vary': 'Accept-Encoding',
'Set-Cookie': 'uuid_tt_dd=10_18804008730-1549645055782-268903; Expires=Thu, 01 Jan 2025 00:00:00 GMT; Path=/; Domain=.csdn.net;',
'Strict-Transport-Security': 'max-age= 31536000',
'Content-Encoding': 'gzip'},
'href': 'https://blog.csdn.net/qq_34243930/rss/list',
'status': 200,
'encoding': 'UTF-8',
'version': 'rss20',
'namespaces': {}}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
基本用法
每个 RSS 和 Atom 订阅源都包含一个标题(d.feed.title)和一组文章条目(d.entries)。
通常,每个文章条目都有一段摘要(d.entries[i].summary),或者是包含了条目中实际文本的描述性标签(d.entries[i].description)。
import feedparser
d=feedparser.parse('https://blog.csdn.net/qq_34243930/rss/list')
- 1
- 2
- d.feed
feed 对应一个字典
import feedparser
d=feedparser.parse('https://blog.csdn.net/qq_34243930/rss/list')
d['feed']['title']
Out[9]: 'Ssummer'
d.feed.title # 通过属性的方式访问
Out[10]: 'Ssummer'
d.feed.link
Out[11]: 'https://blog.csdn.net/qq_34243930'
d.feed.subtitle
Out[12]: '一个小可爱'
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- d.entries
type(d.entries)
Out[18]: list
len(d.entries)
Out[19]: 20 # 共20篇文章
[e.title for e in d.entries][:3]
Out[20]:
['[原]图像处理-图片找不同Find the differences of the two images #Matlab下调用Python接口#SIFT算法应用',
'[原]《斯坦福CS224n NLP》-Week1#',
'[原]《斯坦福CS224n NLP》-Week2#']
d.entries[0].summary # 第一篇文章的摘要信息
Out[21]: '说明\n要求(含待处理图片等)、源代码见CSDN下载:\nPPT展示、英文报告 见CSDN下载:\n大作业要求\n\nTask: Find the differences of the two images, ignoring butterfly\nThe code should be suitable for all image pairs.\n找出经旋转或裁剪之后,像素点并不对应的两幅图片的不同之处。其中不... <div>\n 作者:qq_34243930 发表于 2018/12/28 00:36:22 <a href="https://blog.csdn.net/qq_34243930/article/details/85316240">原文链接</a> https://blog.csdn.net/qq_34243930/article/details/85316240 </div>\n <div>\n 阅读:38 </div>'
d.entries[0].summary == d.entries[0].description
Out[22]: True
# 有些条目可能会不提供 summary 信息
# 此时 summary 信息可通过 description 获得
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
更多使用方法参考:
Python 模块feedparser安装使用:
https://blog.csdn.net/DarrenXf/article/details/82669506
python feedparser 使用:
http://www.cnblogs.com/youxin/archive/2013/06/12/3132713.html