【问题标题】:Iterate through multiple class using find_element_by_class_name in Selenium在 Selenium 中使用 find_element_by_class_name 遍历多个类
【发布时间】:2012-01-07 07:04:21
【问题描述】:

我在 Python 中使用 Selenium webdriver 进行网络抓取项目。

我正在处理的网页有许多具有相同类名的表条目。

<table class="table1 text print">

我正在使用find_element_by_class_name。但是我收到一个错误:

*Compound class names not permitted*

另一个问题:

如何遍历所有具有相同css类名的表?

谢谢

【问题讨论】:

    标签: python selenium webdriver web-scraping


    【解决方案1】:

    您描述的错误发生在您提供多个类名而不是一个类名时。解决此问题的一种简单方法是使用 CSSSelector 或 XPath 获取元素。或者,您可以使用 find_elements_by_class_name 并提供一个类名,然后遍历该列表以查找与您要匹配的其他类名相匹配的元素。

    【讨论】:

      【解决方案2】:

      您应该使用find_elements_by_class_name。这将返回一个可迭代的对象。

      【讨论】:

        猜你喜欢
        • 2017-11-29
        • 1970-01-01
        • 2023-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多