免费建个人网站,上手机淘宝网站建设,怎么样创建自己的小程序,网络营销的基本特征xml 和html 区别
jsonpath模块 场景 多层嵌套的复杂字典直接提取数据 安装
pip install jsonpath使用
from jsonpath import jsonpathret jsonpath(dict, jaonpath语法规则字符串)语法规则 eg:
lxml模块xpath语法
谷歌浏览器 xpath helper 插件
作用对当前页面… xml 和html 区别
jsonpath模块 场景 多层嵌套的复杂字典直接提取数据 安装
pip install jsonpath使用
from jsonpath import jsonpathret jsonpath(dict, jaonpath语法规则字符串)语法规则 eg:
lxml模块xpath语法
谷歌浏览器 xpath helper 插件
作用对当前页面测试xpath语法规则
xpath 语法
1.基础语法 /html/head/title 绝对路径
/html//title. 相对路径
//title 相对于整个html文档
//title/. 当前节点
//title/./../.. 父节点 2.选取特定节点的语法
可以根据标签的属性值下标等来获取特定的节点 节点修饰语法1.通过索引修饰节点/html/body/div[3]/div/div[1]/div/html/body/div[3]/div/div[1]/div[3]/html/body/div[3]/div/div[1]/div[last()]. 选中最后一个/html/body/div[3]/div/div[1]/div[last()-1]. 选中倒数第二个/html/body/div[3]/div/div[1]/div[position() 10]. 范围选择2.通过属性值修饰节点//div[idcontent-left]/div/id出现在[]中的是使用标签属性名和属性值修饰节点3.通过子节点的值修饰节点//span[i2000]//div[span[2]9.4]4.通过包含修饰//div[contains(id, qiushi_tag_)]//span[contains(text(), 一页)]xpath中第一个元素的位置是13.选取未知节点的语法
lxml使用
安装
pip install lxml使用
1.导入lxml的etree库
from lxml import etree
2.利用etree.HTML将html字符串bytes|str转化为Element对象Element对象具有xpath的方法返回结果的列表
html etree.HTML(text)
ret_list html.xpath(xpath语法规则字符串)
3.xpath方法返回列表的三种情况
返回空列表
返回有字符串构成的列表
返回由Element对象构成的列表