Moh*_*ris 7 python selenium selenium-chromedriver selenium-webdriver
这是我遇到的一个奇怪的问题,我在互联网上找不到任何解决方案。我在 google colab 中使用 selenium 来抓取网站,我的代码运行得很好。第二天我醒来,再次运行代码,没有更改任何一行,并且不知道我的代码如何/为什么开始给出此错误,AttributeError:“WebDriver”对象没有属性“find_element_by_link_text”。find_element_by_class_name 和 id 等也是如此。然后我重新检查了以前的工作脚本只是为了确认,这也给了我同样的错误。我对突然发生的事情感到困惑,脚本开始给我这些错误。
我该如何解决这个问题?我在这里做错了什么?
!pip install selenium
!apt-get update
!apt install chromium-chromedriver
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('chromedriver',options=chrome_options)
driver.get("https://petrowiki.spe.org/PetroWiki")
driver.title #this line is returning the correct title value, code is able to access the url
peh = driver.find_element_by_link_text('Pet. Eng. Handbook')
peh.click()
Run Code Online (Sandbox Code Playgroud)
Mic*_*ntz 24
Selenium 刚刚在 version 中删除了该方法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
Run Code Online (Sandbox Code Playgroud)
您现在需要使用:
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
Run Code Online (Sandbox Code Playgroud)
为了提高可靠性,您应该考虑WebDriverWait与 结合使用element_to_be_clickable。
| 归档时间: |
|
| 查看次数: |
18587 次 |
| 最近记录: |