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

InvalidSelectorError: Compound class names not permitted报错处理

时间:2019-06-08 15:12:39      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:ext   name   code   很多   edr   ati   节点   not   perm   

InvalidSelectorError: Compound class names not permitted报错处理

环境:python3.6 + selenium 3.11 +  chromedriver.exe

我们在解析网页的时候,总是会遇到大量的tag,如何精确定位到这些tag,也是有很多的方法。

今天在用 find_element_by_class_name获取一个节点对象时,报了个错 Compound class names not permitted.
技术图片

原始代码:

selected_div = driver.find_element_by_class_name(‘next-pagination next-pagination-normal next-pagination-medium medium pagination‘)

技术图片

修改后的代码:

 selected_div = driver.find_element_by_css_selector("[class=‘next-pagination next-pagination-normal next-pagination-medium medium pagination‘]")

或者:

 selected_div = driver.find_element_by_css_selector(".next-pagination.next-pagination-normal.next-pagination-medium.medium.pagination")

这两段代码都可以正常获取到所需对象。

 

总结:

在获取包含多个class名称的tag对象时

建议使用:

find_element_by_css_selector(".xx.xxx.xxxxx")

或者

find_element_by_css_selector("[class=‘xx xxx xxxxx‘]")

 

InvalidSelectorError: Compound class names not permitted报错处理

标签:ext   name   code   很多   edr   ati   节点   not   perm   

原文地址:https://www.cnblogs.com/111testing/p/10990513.html

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