InvalidSelectorError: Compound class names not permitted报错处理css
环境:python3.6 + selenium 3.11 + chromedriver.exepython
咱们在解析网页的时候,老是会遇到大量的tag,如何精肯定位到这些tag,也是有不少的方法。chrome
今天在用 find_element_by_class_name获取一个节点对象时,报了个错 Compound class names not permitted.spa
原始代码:orm
selected_div = driver.find_element_by_class_name('next-pagination next-pagination-normal next-pagination-medium medium pagination')对象
修改后的代码:blog
selected_div = driver.find_element_by_css_selector("[class='next-pagination next-pagination-normal next-pagination-medium medium pagination']")element
或者:selenium
selected_div = driver.find_element_by_css_selector(".next-pagination.next-pagination-normal.next-pagination-medium.medium.pagination")string
这两段代码均可以正常获取到所需对象。
总结:
在获取包含多个class名称的tag对象时
建议使用:
find_element_by_css_selector(".xx.xxx.xxxxx")
或者
find_element_by_css_selector("[class='xx xxx xxxxx']")