Python库之网络爬虫
**Reques:**最友好的网路爬虫功能库
- 提供了简单易用的类HTTP协议网络爬虫功能
- 支持连接池、SSL、Cookies、HTTP(s)代理等
- Python最主要的页面级网络爬虫功能库
import requests
r = requests.get('https://apo.github.com/user',auth=('user','pass'))
r.status_code //获得访问网页的状态效果
r.headers['content-type']
r.encoding
r.text //获得文本信息
**Scrapy:**优秀的网络爬虫框架,Python数据分析高层次应用库
https://scrapy.org
- 提供了构建网络爬虫系统的框架功能,稍加配置即可使用
- 支持批量和定时网页爬取,提供数据处理流程等
- Python最主要且最专业的网络爬虫框架
**pyspider:**强大的Web页面爬取系统
https://docs.pyspider.org - 提供完整的网页爬取系统构建功能
- 支持数据库后端、消息队列、优先级、分布式框架等
- python重要的网络爬虫类第三方库
Python库之Web信息提取
**Beautiful Soup:**HTML和XML的解析库
- 提供了解析HTML和XML等Web信息的功能
- 可以加载多种解析引擎
- 常与网络爬虫库搭配使用
https://www.crummy.com/software/BeattifulSoup/bs4
**Re:**正则表达式解析和处理功能库
https://docs.python.org/3.6/library/re.html - 提供了定义和解析正则表达式的功能
- 可用于各类场景,包括定点的Web信息提取
**Python-Goose:**提取文章类型的Web页面的功能库 - 提供了对Web页面中文章信息/视频等元数据的提取功能
- 针对特定类型的Web页面,应用覆盖面广
//获取标题、正文等元素
from goose import Goose
url = 'xxxxxx'
g = Goose({use_meta_language':False, 'target_language':'es'})
article = g.extract(url=url)
article.cleaned_text[:150]
Python库之Web网站开发
**Django:**最流行的Web应用框架
- 提供了构建Web系统的基本应用框架
- MTV模式:模型(model)、模板(Template)、视图(Views)
- 专业级应用框架
https://djangoproject.com
**Pyramid:**规模适中的Web应用框架 - 提供了简单的Web系统应用框架
- 适合快速构建并适度扩展
https://trypyramid.com
//实现hello world
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
def hello_world(request):
return Response('Hello World')
if __name__ = '__main__':
with Configurator() as config:
config.add_route('hello','/')
config.add_view(hello_world,route_name='hello')
app = config.make_wsgi_app()
server = make_server('0,0,0,0',6543,app)
server.server_forever()
**Flask:**Web应用开发框架
- 最简单的Web开发框架
- 简单、规模小、快速
http://flask.pocoo.org
//实现hello world
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello,World'
Python库之网络应用开发
**WeRoBot:**微信公众号开发框架
- 解析微信服务器消息及反馈消息的功能
- 建立微信机器人的手段
//对每一个微信消息返回特定信息
import werobot
robot = werobot.WeRoBot(token='tokenhere')
@robot.handler
def hello(message):
return 'Hello world'
**aip:**百度AI开放平台接口
- 提供了访问百度AI服务器的Python功能接口
- 语音、人脸等领域
**MyQR:**二维码生成库