火车头浏览器xpath常用技巧

作者:admin   时间:2020-06-18   访问量:615

  xpath常用技巧

  starts-with 选取id值以ma开头的div节点。例: //div[starts-with(@id,”ma”)]

  contains 选取id值包含ma的div节点。 例://div[contains(@id,”ma”)]

  文字:div[contains(.,'网络')]

  and 选取id值包含ma和in的div节点。 例://div[contains(@id,”ma”) and contains(@id,”in”)]

  text() 选取节点文本包含ma的div节点。 例://div[text()='ma']

  not 排除某个节点。例://tbody/tr[not(@class)],//tbody/tr[not(@class or @id)]

  /bookstore/book[1] 选取属于 bookstore 子元素的第一个 book 元素。

  /bookstore/book[last()] 选取属于 bookstore 子元素的最后一个 book 元素。

  /bookstore/book[last()-1] 选取属于 bookstore 子元素的倒数第二个 book 元素。

  /bookstore/book[position()<3] 选取最前面的两个属于 bookstore 元素的子元素的 book 元素。

  /bookstore/book[price>35.00] 选取 bookstore 元素的所有 book 元素,且其中的 price 元素的值须大于 35.00。

  xpath经典案例

  根据子级定位父级(..): //div[contains(@class,'lonon-pagination-wrap')]//i/..

  相邻兄弟节点:

  a、following-sibling://table[@id="oddsList_tab"]//tr[contains(.,'bet 365')]/following-sibling::tr[1]

  b、preceding-sibling://table[@id="oddsList_tab"]//tr[contains(.,'bet 365')]/preceding-sibling::tr[1]

  去除文本中的前后空格和回车:

  //a[normalize-space(text())='货运表现']

  百度竞价广告定位://div[div//span[contains(.,'csldhg')]][@cmatchid]

  定位包含特定子元素的元素://a[./h3]


【地址】:http://www.inseo.cn/seo/8.html转载请注明出处


相关文章

Copyright © 2018-2030 大树SEO All Rights Reserved.