AttributeError:“WebDriver”对象没有属性“find_element_by_class_name”

问题描述 投票:0回答:1

我想提取这台机器的价格。 https://www.amazon.com/dp/B01N7GO468/ref=syn_sd_onsite_desktop_217?psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEyOTE3T1VVUk5UOVBXJmVuY3J5cHRlZElkPUEwNjg4MzM2MkZJUEJXTU 1NT1FBQiZlbmNyeXB0ZWRBZElkPUEwMjQ2NzE1MUVQNEU3Tkk5VjJROSZ3aWRnZXROYW1lPXN kX29uc2l0ZV9kZXNrdG9wJmFjdGlvbj1jbGlja1JlZGlyZWN0JmRvTm90TG9nQ2xpY2s9dHJ1 ZQ==。 当我尝试通过硒提取价格时,它给了我错误: AttributeError:“WebDriver”对象没有属性“find_element_by_class_name”。

python selenium-webdriver web-scraping webdriver
1个回答
1
投票

Selenium 刚刚在版本

4.3.0
中删除了该方法。查看更改:https://github.com/SeleniumHQ/selenium/blob/a4995e2c096239b42c373f26498a6c9bb4f2b3e7/py/CHANGES

Selenium 4.3.0
* Deprecated find_element_by_* and find_elements_by_* are now removed (#10712)
* Deprecated Opera support has been removed (#10630)
* Fully upgraded from python 2x to 3.7 syntax and features (#10647)
* Added a devtools version fallback mechanism to look for an older version when mismatch occurs (#10749)
* Better support for co-operative multi inheritance by utilising super() throughout
* Improved type hints throughout

您现在需要使用:

from selenium.webdriver.common.by import By

driver.find_element(By.CLASS_NAME, THE_CLASS_NAME)

或者没有额外的导入:

driver.find_element("class name", THE_CLASS_NAME)

为了提高可靠性,您应该考虑将

WebDriverWait
element_to_be_clickable
结合使用。

© www.soinside.com 2019 - 2024. All rights reserved.