用Python抓取网页并解析

软件版本html


python:2.7.12html5

网页抓取库python


网页抓取库为requests,git

github地址为:https://github.com/requests/requestsgithub

文档地址为:http://docs.python-requests.org/en/master/spa

安装很简单,直接使用pipcode

pip install requests

网页解析库xml


网页解析库使用beautifulsoup4,其支持多种html解析器,如html5lib,lxml,须要一并安装,推荐使用lxml网页解析器htm

安装过程以下:blog

pip install beautifulsoup4
pip install lxml
pip install html5lib

使用方法:

soup = BeautifulSoup(html_content, "lxml", from_encoding="utf-8")

详细使用方法见《Beautiful Soup 4.4.0 文档》及他人博文《python:BeautifulSoup 模块使用指南

相关文章
相关标签/搜索