xpath的匹配规则

starts-with 匹配一个属性开始位置的关键字

contains 匹配一个属性值中包含的字符串

text() 匹配的是显示文本信息,此处也可以用来做定位用

i.e.

//input[starts-with(@name,'name1')]     查找name属性中开始位置包含'name1'关键字的页面元素

//input[contains(@name,'na')]         查找name属性中包含na关键字的页面元素

<a href="http://www.baidu.com">百度搜索</a>

xpath写法为 //a[text()='百度搜索'] 

或者 //a[contains(text(),"百度搜索")]

1、获取属性值

sel.xpath('./dt/@id').extract()

原文地址:https://www.cnblogs.com/shengulong/p/7991701.html