解決關於使用Selenium WebDriver 在Python打開瀏覽器時出錯

錯誤1:

Traceback (most recent call last):
File "E:/codes/python/script.py", line 5, in <module>
driver.get("http://www.python.org")
TypeError: get() missing 1 required positional argument: 'url'

錯誤2:

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81

解決辦法:
使用webdrive管理器解決這類問題。
您可以使用webdrive-manager自動使用正確的chromedriver。安裝webdrive-manager:

pip install webdriver-manager

然後如下所示在python中使用驅動程序

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())

實例:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('http://quanluo.github.io/')
driver.get_screenshot_as_file("123.png")
driver.quit()
# driver.close()
print('ok')

得到網頁截圖:
在這裏插入圖片描述
表明問題已解決。


我的個人博客:https://quanluo.github.io

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章