xpath定位方式实例

来源:互联网 发布:淘宝代销可以改价格吗 编辑:程序博客网 时间:2024/06/16 09:13

xpath定位方式实例

xpath学习:
https://www.w3cschool.cn/xpath/xpath-xpath-tutorialij9m1t5i.html

1,id定位
通过Id

 xpath("//input[@id='username']")

2,不同标签
这里写图片描述

xpath("//a[@id='tu']")

3,使得页面元素的文本定位
这里写图片描述

//a[contains(text(),'页面运营')]

通过@属性

//img[contains(@alt,'g1')]

4,轴定位 (不太常用)
这里写图片描述

下图四种定位方式
这里写图片描述

以上是UI自动化中的定位

爬虫中xpath选择器

1,爬虫中的xpath筛选 排除某个
这里写图片描述
排除红框处span的,定位到其他span

//div[@class='cp-products']/div[@class='right']/span[not(@itemprop= 'productionDate')]

其他实例

xpath("//span[contains(@class, 'vote-post-up')]/h10/text()")xpath('//div[@class="entry-header"]/h1/text()')
原创粉丝点击