码迷,mamicode.com
首页 > 其他好文 > 详细

selenium抓取元素排除某个特定的class标签

时间:2015-08-13 16:07:41      阅读:359      评论:0      收藏:0      [点我收藏+]

标签:

排除某个因素,第一优选想到正则表达式,无奈折腾半天没有成功,感觉是selenium对元素的attrs按re search在操作,$对字符串末尾检测都没什么用。

BeautifulSoup可以用element[‘class’]输出元素的class进行检测,但是BeautifulSoup对象不能再进行click操作,不符合期望。selenium没有这样的语法,通过xpath进行选择:

itemList = driver.find_elements_by_xpath(‘//div[@id = "choose-color"]//div[@class = "dd"]//div[not(contains(@class, "disabled"))]‘)

stackoverflow有个参考:http://stackoverflow.com/questions/11024080/how-to-use-not-contains-in-xpath


补充xpath用法:

xpath=xpathExpression: Locate an element using an XPath expression.  
  
xpath=//img[@alt=’The image alt text’]  
xpath=//table[@id=’table1’]//tr[4]/td[2]  
xpath=//a[contains(@href,’#id1’)]  
xpath=//a[contains(@href,’#id1’)]/@class  
xpath=(//table[@class=’stylee’])//th[text()=’theHeaderText’]/../td  
xpath=//input[@name=’name2’ and @value=’yes’]  
xpath=//*[text()=”right”]


selenium抓取元素排除某个特定的class标签

标签:

原文地址:http://my.oschina.net/u/2420420/blog/491816

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!