首页 技术 正文
技术 2022年11月21日
0 收藏 577 点赞 5,001 浏览 776 个字

前情提要:

  上节学过从网上获取请求,获取返回内容,带理

获取内容之后,第二部就是获取请求的数据分析

  一:xpath 语法

 浏览器一般会自带xpatn 解析

这里大概讲述一下xpath 的基本操作

请求数据分析 xpath语法 与lxml库

请求数据分析 xpath语法 与lxml库

请求数据分析 xpath语法 与lxml库

请求数据分析 xpath语法 与lxml库

请求数据分析 xpath语法 与lxml库

二:式例

我用的是360 浏览器…(..用了好多年了..习惯了..)

我们拿笔趣阁进行测试

https://www.biquge5200.cc/46_46254/

1>进入开发者模式

2>写xpath

请求数据分析 xpath语法 与lxml库

 >2.1

  //        获取子孙节点

    div        div  节点

  //          获取上一层下的子孙节点

  dl          dl  节点

  //            获取上一层下的子孙节点

  dd         dd节点

  [position()]             节点内的位置

  >                            比较运算符

  9                             第九个节点

三: lxml 解析器

请求数据分析 xpath语法 与lxml库

# 本地使用
# from lxml import etree
# htmlElent =etree.HTML(text)
# print(type(htmlElent)) #html对象
# print(etree.tostring(htmlElent,encoding='utf-8').decode('utf-8'))# etree.tostring 规范化并补全#读取文件中的html
# from lxml import etree
# parser =etree.HTMLParser(encodeing=('utf-8')) #定义解析器
# #解析器作用 补全html 和规范html
# htmlElent =etree.parse("lagou.html",parser=parser)
# # 读取本地html 文件. 传入解析器
# print(etree.tostring(htmlElent,encoding='utf-8').decode('utf-8'))
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,986
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,502
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,346
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,129
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,764
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,841