Python 模块feedparser安装使用
RSS(简易信息聚合)
简易信息聚合(也叫聚合内容)是一种RSS基于XML标准,在互联网上被广泛采用的内容包装和投递协议。RSS(Really Simple Syndication)是一种描述和同步网站的内容格式,是使用最广泛的XML应用。RSS搭建了信息迅速传播的一个技术平台,使得每个人都成为潜在的信息提供者。
安装
$ pip install feedparser
feedparser 使我们轻松实现从任何RSS或者Atom订阅源得到标题、链接和文章的条目。
具体测试
import feedparser
def test(url='http://blog.csdn.net/together_cz/article'):
print('url:%s' % one_url)
page_dict = feedparser.parse(url)
''' 解析得到的是一个字典 '''
#print page_dict
'''
输出字典中的键值有哪些,一共有10中如下:
['feed', 'status', 'version', 'encoding', 'bozo', 'headers', 'href', 'namespaces', 'entries', 'bozo_exception']
'''
print page_dict.keys()
print '#####################################################################'
print '访问页面链接 href:'
print page_dict['href']
print '返回headers:'
print page_dict['headers']
print 'ersion信息为:'
print page_dict['version']
print '状态码为:'
print page_dict['status']
fd = page_dict.get('feed','')
for key in fd.keys():
print key
print '语言类型为:'
print page_dict['feed']['html']['lang']
print 'meta信息为:'
print page_dict['feed']['meta']['content']
print page_dict['feed']['meta']['name']
print '#####################################################################'
if __name__ == '__main__':
url_list=['http://www.baidu.com',
'http://www.jd.com',
'http://www.vmall.com',
'http://www.taobao.com']
for one_url in url_list:
try:
test(one_url)
except:
print '????????????????????????????????????????????????????????????'
输出
url:http://www.baidu.com
['feed', 'status', 'version', 'encoding', 'bozo', 'headers', 'href', 'namespaces', 'entries', 'bozo_exception']
#####################################################################
访问页面链接 href:
http://www.baidu.com
返回headers:
{'content-length': '2701', 'content-type': 'text/html', 'content-encoding': 'gzip'}
ersion信息为:
状态码为:
200
meta
summary
语言类型为:
????????????????????????????????????????????????????????????
url:http://www.jd.com
['feed', 'status', 'version', 'encoding', 'bozo', 'headers', 'href', 'namespaces', 'entries', 'bozo_exception']
#####################################################################
访问页面链接 href:
https://www.jd.com/
返回headers:
{'content-length': '28099', 'via': 'BJ-Y-NX-105(HIT), http/1.1 CD-CT-1-JCS-42 ( [cRs f ])', 'ser': '13.215', 'content-encoding': 'gzip', 'age': '24', 'expires': 'Wed, 12 Sep 2018 14:23:27 GMT', 'vary': 'Accept-Encoding', 'server': 'JDWS/2.0', 'connection': 'close', 'strict-transport-security': 'max-age=3600', 'cache-control': 'max-age=30', 'date': 'Wed, 12 Sep 2018 14:23:45 GMT', 'content-type': 'text/html; charset=utf-8'}
ersion信息为:
状态码为:
302
html
meta
links
script
语言类型为:
zh-CN
meta信息为:
webkit
renderer
#####################################################################
url:http://www.vmall.com
['feed', 'status', 'version', 'encoding', 'bozo', 'headers', 'href', 'namespaces', 'entries', 'bozo_exception']
#####################################################################
访问页面链接 href:
http://www.vmall.com
返回headers:
{'content-length': '781', 'connection': 'Keep-Alive', 'content-encoding': 'gzip'}
ersion信息为:
状态码为:
200
语言类型为:
????????????????????????????????????????????????????????????
url:http://www.taobao.com
['feed', 'status', 'version', 'encoding', 'bozo', 'headers', 'href', 'etag', 'namespaces', 'entries', 'bozo_exception']
#####################################################################
访问页面链接 href:
https://www.taobao.com/
返回headers:
{'x-swift-savetime': 'Wed, 12 Sep 2018 14:19:11 GMT', 'x-swift-cachetime': '300', 'x-cache': 'HIT TCP_MEM_HIT dirn:6:607364846 mlen:-1', 'content-encoding': 'gzip', 'transfer-encoding': 'chunked', 'vary': 'Accept-Encoding, Ali-Detector-Type', 'age': '274', 'strict-transport-security': 'max-age=31536000', 'eagleid': 'b68cf51715367622259114055e', 'server': 'Tengine', 'cache-control': 'max-age=60, s-maxage=300', 'connection': 'close', 'via': 'cache5.l2wt97[80,304-0,C], cache13.l2wt97[66,0], cache9.cn172[0,200-0,H], cache9.cn172[1,0]', 'etag': 'W/"2a36-165c95cc45b"', 'set-cookie': 'thw=cn; Path=/; Domain=.taobao.com; Expires=Thu, 12-Sep-19 14:23:45 GMT;', 'date': 'Wed, 12 Sep 2018 14:23:45 GMT', 'content-md5': 's6hP5DCqrrp9rS7Tz3jT+w==', 'content-type': 'text/html; charset=utf-8', 'timing-allow-origin': '*', 'x-snapshot-age': '2'}
ersion信息为:
状态码为:
302
links
meta
summary
html
link
base
语言类型为:
zh-CN
meta信息为:
淘宝,掏宝,网上购物,C2C,在线交易,交易市场,网上交易,交易市场,网上买,网上卖,购物网站,团购,网上贸易,安全购物,电子商务,放心买,供应,买卖信息,网店,一口价,拍卖,网上开店,网络购物,打折,免费开店,网购,频道,店铺
keyword
#####################################################################
Python 模块feedparser安装使用的更多相关文章
- python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheetahcherrypy:一个WEB frameworkctype ...
- 常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件 bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheetahcherrypy:一个WEB frameworkctyp ...
- Python 模块chardet安装过程(windows环境)
最近需要一个txt文件的批量转码功能,在网上找到一段批量处理java源文件的py程序如下: #-*- coding: utf-8 -*- import codecs import os import ...
- Python 模块chardet安装 setup.py
http://pypi.python.org/pypi/chardet#downloads 下载chardet-2.*.*.tar.gz:解压到site-package文件夹, Python及其一些模 ...
- python模块的安装
1.下载所需模块 2.解压到一个目录 3.window下打开cmd 4.切换到模块setup.py目录 5.执行python setup.py install安装 前提是安装了python,并且配置了 ...
- Python模块如何安装 并确认模块已经安装好?
看自己有没有安装好,最简单的办法在可以再控制台下: C:\Users\sony>python Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC ...
- Python 模块的安装与使用
我们知道使用函数不仅减轻了工作量,而且使代码更加简洁,更加的易于维护.但如果在另一个文件中,我们希望使用上一个文件中定义的某个函数,我们应该怎么办呢?我们需要重新将上一个函数再次实现一遍吗?而且,当我 ...
- python模块一键安装
利用bat文件 在不懂电脑的小白电脑上一键安装你python环境所需要的模块(你想让她一个个安装,你会疯的) 先新建一个txt文件,把你需要安装的模块和版本号写进去: 然后再新建一个txt文件 然后把 ...
- python模块 mysql-python安装(在ubuntu系统下)
直接运行如下命令 sudo pip install MySQL-python 报如下错误 xxx@ubuntu:~$ sudo pip install MySQL-python Downloading ...
随机推荐
- PHP设计模式之模板方法模式
模板方法模式,也是我们经常会在不经意间有会用到的模式之一.这个模式是对继承的最好诠释.当子类中有重复的动作时,将他们提取出来,放在父类中进行统一的处理,这就是模板方法模式的最简单通俗的解释.就像我们平 ...
- webpack learn1-配置项目加载各种静态资源及css预处理器2
继续在webpack.config.js中配置loader { test:/\.css$/, use: [ 'style-loader', 'css-loader' ] },{ test:/\.(jp ...
- 怎样在Linux中查看apache是用那个httpd.conf
第一步:找到apache启动命令: [root@WAPBJ01 ~]# ps -ef|grep httpdroot 10575 1 0 19:45 ? 00:00:03 ...
- SpringBoot 如何进行对象复制,老鸟们都这么玩的!
大家好,我是飘渺. 今天带来SpringBoot老鸟系列的第四篇,来聊聊在日常开发中如何优雅的实现对象复制. 首先我们看看为什么需要对象复制? 为什么需要对象复制 如上,是我们平时开发中最常见的三层M ...
- Xshell和Xftp - 下载安装
简介 Xshell 实际工作运用:连接Linux Xftp 实际工作运用:传输文件到Linux系统 下载安装 三连后评论区留言私发,此贴长期有效!!!
- 为Python安装Redis库
为Python安装Redis库,登陆https://github.com/andymccurdy/redis-py 后点击Download ZIP下载安装包. 解压并安装: git clone htt ...
- pyQt5设计无边框窗口(二)
无边框,自定义窗口背景 from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * impor ...
- 不关闭selinux下配置php+httpd访问KingbaseES
在不关闭selinux的情况下使httpd+php+KingbaseES正常使用1.正常设置php.apache 除了正常流程外还需要在/etc/sysconfig/httpd最后追加LD_LIBRA ...
- P3971-[TJOI2014]Alice and Bob【贪心】
正题 题目链接:https://www.luogu.com.cn/problem/P3971 题目大意 一个\(1\sim n\)的一个排列,设\(a_i\)表示以\(i\)结尾的最长上升子序列长度, ...
- 项目配置shiro原缓存注解失效
项目用springboot + shiro + ehcache @cacheable 注解不起作用原因 Shiro框架初始化比Spring框架的某些部件早,导致使用@Autowire注入Shiro框架 ...