解决关于使用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')

得到网页截图:
解决关于使用Selenium WebDriver 在Python打开浏览器时出错_第1张图片
表明问题已解决。


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

你可能感兴趣的:(Python,python,selenium,chrome,pip)