请教:python通过xpath该怎么获取呐

res = driver.find_elements_by_xpath('//div[contains(text(),"运单管理")]')
我这样写打印的是空
回答:
你的 XML 节点结构是这样的:
<div>  <span>
  <img>
  " 运单管理"
</div>
而 text() 无法处理含有节点集的内容(也就是 <div> 标签内的 <span>、<img>),所以你应该使用 string() 来抓取:'//div[contains(string(),"运单管理")]'。
想要了解更多的话,可以去查查 text() 和 string() 两个方法的区别。
回答:
你得熟悉xpath的计算规则,否则做这个很难
以上是 请教:python通过xpath该怎么获取呐 的全部内容, 来源链接: utcz.com/a/162924.html

