当前位置:网站首页>lxml模块(数据提取)
lxml模块(数据提取)
2022-07-01 06:17:00 【HHYZBC】
lxml 是 Python 的第三方解析库,在第一次使用前需要使用到下面命令进行下载
pip install lxmllxml使用流程
lxml模块中提供了一个etree 模块,该模块专门用于解析HTML/XML 文档
- 导入模块
from lxml import etree- 初始化解析对象
parse_html = etree.HTML(html)HTML() 方法能够将 HTML 标签字符串解析为 HTML 文件,该方法可以自动修正 HTML 文本。parse_html只是一个变量名,后续的调用xpath表达式都是在此对象的基础上完成的。
- 调用xpath表达式
r_list = parse_html.xpath('xpath表达式')xpath方法会将符合xpath表达式的结果以列表的形式返回。
xpath表达式
常用的路径表达式
- nodename
- 选取此节点的所有子节点。
- /
- 从根节点选取。
- //
- 从匹配选择的当前节点选择文档中的节点,而不考虑它们的位置。
- .
- 选取当前节点。
- ..
- 选取当前节点的父节点。
- @
- 选取属性。
常用方法
- text()
- 返回该节点的的数据,如:
<a href="#">哈哈哈</a>- 使用text()方法后会返回哈哈哈
更多函数看官网:
XPath 教程 (w3school.com.cn)
https://www.w3school.com.cn/xpath/index.asp
边栏推荐
- Make Tiantou village sweet. Is Xianjing taro or cabbage the characteristic agricultural product of Tiantou Village
- Servlet
- Record currency in MySQL
- Save data in browser to local file
- 阶乘约数(唯一分解定理)
- Small guide for rapid completion of mechanical arm (VI): stepping motor driver
- 【ManageEngine】终端管理系统,助力华盛证券数字化转型
- libpng12.so. 0: cannot open shared object file: no such file or directory
- 机械臂速成小指南(六):步进电机驱动器
- 69 cesium code datasource loading geojson
猜你喜欢

Index method and random forest to realize the information of surface water body in wet season in Shandong Province

【文件系统】如何在ubi之上运行squashfs

2022 年面向初学者的 10 大免费 3D 建模软件

What if the data in the cloud disk is harmonious?

Freeswitch dial the extension number

Movable mechanical wall clock

B-树系列

69 Cesium代码datasource加载geojson

three. JS summary

JDBC database operation
随机推荐
机械臂速成小指南(六):步进电机驱动器
Essay learning record essay multi label Global
交换机配置软件具有的作用
Transformer le village de tiantou en un village de betteraves sucrières
做技术,自信不可或缺
3D打印机穿线:5种简单的解决方案
【ManageEngine】终端管理系统,助力华盛证券数字化转型
69 cesium code datasource loading geojson
highmap gejson数据格式转换脚本
Tidb database characteristics summary
Servlet
[note] e-commerce order data analysis practice
Although pycharm is marked with red in the run-time search path, it does not affect the execution of the program
Top 10 Free 3D modeling software for beginners in 2022
Linux closes the redis process SYSTEMd+
MongoDB:一、MongoDB是什么?MongoDB的优缺点
ArcServer密码重置(账号不可以重置)
Fixed height of the first column in El table dynamic header rendering
Tidb single machine simulation deployment production environment cluster (closed pit practice, personal test is effective)
skywalking集成nacos动态配置