xpath和css选择器的部分简单使用方法

xpath的部分用法

not关键字的使用

匹配class为content_con的下除了class值为xgwz之外的所有内容,(*匹配所有,也可指定标签例如div)
//div[@class='content_con']/*[not(@class='xgwz')]

选择不包含class属性的节点
//span[not(@class)]

选择不包含class和id属性的节点
//span[not(@class) and not(@id)]

选择不包含class="expire"的span
//span[not(contains(@class,'expire'))]

选择包含class="expire"的span
//span[contains(@class,'expire')]

contains 关键字的使用

匹配class值包含info_time的所有div
//div[contains(@class,'info_time')]

position()的使用

寻找li标签,从第二个开始,后面的所有
//div[@class='content_nr']/ul/li[position()>2]

css的部分用法

not关键字的使用

选择class的值为article的div下的所有排除div标签
div.article > :not(div)

nth-child(1) 的使用

选择class为article下的第二个p标签
div.article > p:nth-child(2)
原文地址:https://www.cnblogs.com/ppwang06/p/xpath_css.html