selenium.common.exceptions.WebDriverException: Message: newSession解决方案

 这是报的错误:

Traceback (most recent call last):
  File "D:\python-professional-workplace\pycharm projest\ArticleSpider\lib\site-packages\twisted\internet\defer.py", line 1386, in _inlineCallbacks
    result = g.send(result)
  File "D:\python-professional-workplace\pycharm projest\ArticleSpider\lib\site-packages\scrapy\crawler.py", line 81, in crawl
    start_requests = iter(self.spider.start_requests())
  File "D:\python--\scrapytest\Scripts\scrapypy3\Scripts\ArticleSpider\ArticleSpider\spiders\zhihu.py", line 68, in start_requests
    browser = webdriver.Firefox(executable_path="D:/python--/geckodriver.exe")
  File "D:\python-professional-workplace\pycharm projest\ArticleSpider\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 162, in __init__
    keep_alive=True)
  File "D:\python-professional-workplace\pycharm projest\ArticleSpider\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "D:\python-professional-workplace\pycharm projest\ArticleSpider\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
File "D:\python-professional-workplace\pycharm projest\ArticleSpider\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "D:\python-professional-workplace\pycharm projest\ArticleSpider\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: newSession

 

解决方法:

1、我用的浏览器是火狐浏览器,主要原因是geckodriver的版本太低,而浏览器的版本是64.0。

更新为v0.23.0:https://github.com/mozilla/geckodriver/releases

将下载下来的geckodriver.exe放入python安装路径下的Scripts文件夹内。

注:我是搭建了虚拟环境,所以geckodriver.exe放在了虚拟环境下的文件夹内,没有放在scripts文件下。

2、更新selenium的版本(我是先更新的selenium再更新的geckodriver,所以不太清楚只更新geckodriver是否有用,但只更新selenium没啥用)

分别是:

pip show selenium
python -m pip install --upgrade pip
pip install -U selenium

 更新完在pycharm中更新selenium。

selenium.common.exceptions.WebDriverException: Message: newSession解决方案_第1张图片

 

 

 

 

 

 

你可能感兴趣的:(selenium.common.exceptions.WebDriverException: Message: newSession解决方案)