- 授权协议: MIT
- 开发语言: Python HTML/CSS
- 操作系统: 跨平台
- 软件首页: http://html.python-requests.org/
- 软件文档: http://html.python-requests.org/
- 官方下载: https://github.com/kennethreitz/requests-html/releases
软件介绍
Requests-HTML 对 PyQuery、requests、lxml 等库。
requests-html 具有以下特性
完全支持 JavaScript
CSS 选择器
XPath 选择器
模拟用户代理(如同真正的网络浏览器)
自动跟踪重定向
连接池和 cookie 持久化
安装
pip install requests-html
使用方法
>>> from requests_html import session
# 返回一个Response对象
>>> r = session.get('https://python.org/')
# 获取所有链接
>>> r.html.links
{'/users/membership/', '/about/gettingstarted/'}
# 使用css选择器的方式获取某个元素
>>> about = r.html.find('#about')[0]
>>> print(about.text)
About
Applications
Quotes
Getting Started
Help
Python Brochure还有一个非常吸引人的特点是,它能将 HTML 转换为 Markdown 文本
# 将html转换为Markdown文本 >>> print(about.markdown) * [About](/about/) * [Applications](/about/apps/) * [Quotes](/about/quotes/) * [Getting Started](/about/gettingstarted/) * [Help](/about/help/) * [Python Brochure](http://brochure.getpython.info/)
