簡體   English   中英

AttributeError:“WebDriver”對象沒有屬性“find_element_by_class_name”

[英]AttributeError: 'WebDriver' object has no attribute 'find_element_by_class_name'

我想提取這台機器的價格。 https://www.amazon.com/dp/B01N7GO468/ref=syn_sd_onsite_desktop_217?psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEyOTE3T1VVUk5UOVBXJmVuY3J5cHRlZElkPUEwNjg4MzM2MkZJUEJXTU1NT1FBQiZlbmNyeXB0ZWRBZElkPUEwMjQ2NzE1MUVQNEU3Tkk5VjJROSZ3aWRnZXROYW1lPXNkX29uc2l0ZV9kZXNrdG9wJmFjdGlvbj1jbGlja1JlZGlyZWN0JmRvTm90TG9nQ2xpY2s9dHJ1ZQ== . 當我嘗試通過 selenium 提取價格時,它給了我錯誤:AttributeError:'WebDriver'對象沒有屬性'find_element_by_class_name'。

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)

為了提高可靠性,您應該考慮將WebDriverWaitelement_to_be_clickable結合使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM