<i id='A4nmd'><tr id='A4nmd'><dt id='A4nmd'><q id='A4nmd'><span id='A4nmd'><b id='A4nmd'><form id='A4nmd'><ins id='A4nmd'></ins><ul id='A4nmd'></ul><sub id='A4nmd'></sub></form><legend id='A4nmd'></legend><bdo id='A4nmd'><pre id='A4nmd'><center id='A4nmd'></center></pre></bdo></b><th id='A4nmd'></th></span></q></dt></tr></i><div id='A4nmd'><tfoot id='A4nmd'></tfoot><dl id='A4nmd'><fieldset id='A4nmd'></fieldset></dl></div>
<legend id='A4nmd'><style id='A4nmd'><dir id='A4nmd'><q id='A4nmd'></q></dir></style></legend>
<tfoot id='A4nmd'></tfoot>
    1. <small id='A4nmd'></small><noframes id='A4nmd'>

        <bdo id='A4nmd'></bdo><ul id='A4nmd'></ul>

      1. selenium.common.exceptions.WebDriverException:消息:通过 Python 使

        时间:2023-06-05

          <small id='5fbVD'></small><noframes id='5fbVD'>

          <tfoot id='5fbVD'></tfoot>
              <bdo id='5fbVD'></bdo><ul id='5fbVD'></ul>

            • <legend id='5fbVD'><style id='5fbVD'><dir id='5fbVD'><q id='5fbVD'></q></dir></style></legend>

                <i id='5fbVD'><tr id='5fbVD'><dt id='5fbVD'><q id='5fbVD'><span id='5fbVD'><b id='5fbVD'><form id='5fbVD'><ins id='5fbVD'></ins><ul id='5fbVD'></ul><sub id='5fbVD'></sub></form><legend id='5fbVD'></legend><bdo id='5fbVD'><pre id='5fbVD'><center id='5fbVD'></center></pre></bdo></b><th id='5fbVD'></th></span></q></dt></tr></i><div id='5fbVD'><tfoot id='5fbVD'></tfoot><dl id='5fbVD'><fieldset id='5fbVD'></fieldset></dl></div>
                  <tbody id='5fbVD'></tbody>
                • 本文介绍了selenium.common.exceptions.WebDriverException:消息:通过 Python 使用 Selenium 与 ChromeDriver 和 Chrome 的会话 ID 无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Selenium 编写一些代码,有一次我向不同的网站发出 7 个请求.对于第一个,这很好用.但是,对于其他人,我收到会话 ID 错误.我认为我的浏览器配置正确,因为我确实从第一个网站获得了结果.我试图在请求之间放置一个 WebDriverWait,但无济于事.我认为这些网站可能会阻止我的请求.有谁知道如何解决这个问题?

                  I'm writing some code using Selenium, and at one point I make 7 requests, all to different websites. For the first one, this works fine. However, for others, I get a session ID error. I think that my browser is configured correctly, as I do get results from the first website. I have tried to put a WebDriverWait in between the requests, but to no avail. I think the websites might be blocking my requests. Does anyone have any idea how to solve this problem?

                  如果这是愚蠢的事情或者我做错了什么,我很抱歉,我是新手^^

                  I'm sorry if this is something stupid or if I'm doing anything wrong, I'm quite new ^^

                  提前致谢!

                  Traceback (most recent call last):
                    File "/home/cena/PycharmProjects/Frikandelbroodje/main.py", line 56, in <module>
                      dirk_price = get_price(dirk_url, dirk_classname)
                    File "/home/cena/PycharmProjects/Frikandelbroodje/main.py", line 44, in get_price
                      browser.get(url)
                    File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
                      self.execute(Command.GET, {'url': url})
                    File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
                      self.error_handler.check_response(response)
                    File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
                      raise exception_class(message, screen, stacktrace)
                  selenium.common.exceptions.WebDriverException: Message: invalid session id
                    (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 4.15.0-50-generic x86_64)
                  

                  推荐答案

                  无效的会话 ID

                  无效的会话 ID 错误是 当服务器无法识别唯一会话标识符时发生的 WebDriver 错误.如果会话已被删除会话 ID 无效,则会发生这种情况.

                  invalid session id

                  The invalid session ID error is a WebDriver error that occurs when the server does not recognize the unique session identifier. This happens if the session has been deleted or if the session ID is invalid.

                  可以通过以下任一方式删除 WebDriver 会话:

                  A WebDriver session can be deleted through either of the following ways:

                  • 显式会话删除:当显式调用 quit() 方法时,WebDriver 会话被显式删除,如下所示:

                  • Explicit session deletion: A WebDriver session is explicitly deleted when explicitly invoking the quit() method as follows:

                  • 代码块:

                  • Code Block:

                  from selenium import webdriver
                  from selenium.common.exceptions import InvalidSessionIdException
                  
                  driver = webdriver.Chrome(executable_path=r'C:UtilityBrowserDriverschromedriver.exe')
                  print("Current session is {}".format(driver.session_id))
                  driver.quit()
                  try:
                      driver.get("https://www.google.com/")
                  except Exception as e:
                      print(e.message)
                  

                • 控制台输出:

                • Console Output:

                  Current session is a9272550-c4e5-450f-883d-553d337eed48
                  No active session with ID a9272550-c4e5-450f-883d-553d337eed48
                  

                • 隐式会话删除:当您关闭最后一个窗口或选项卡调用 close() 方法时,会隐式删除 WebDriver 会话,如下所示:

                  Implicit session deletion: A WebDriver session is implicitly deleted when you close the last window or tab invoking close() method as follows:

                  • 代码块:

                  • Code Block:

                  driver = webdriver.Chrome(executable_path=r'C:UtilityBrowserDriverschromedriver.exe')
                  print("Current session is {}".format(driver.session_id))
                  # closes current window/tab
                  driver.close()
                  try:
                      driver.get("https://www.google.com/")
                  except Exception as e:
                      print(e.message)
                  

                • 控制台输出:

                • Console Output:

                  Current session is a9272550-c4e5-450f-883d-553d337eed48
                  No active session with ID a9272550-c4e5-450f-883d-553d337eed48
                  

                • 由于第一个请求工作正常,但对于其他请求,您会收到 会话 ID 错误,很可能是 WebDriver 控制的 Web 浏览器 正在被检测到并因此阻止下一个请求.

                  As the first one request works fine but for others you get a session ID error most possibly the WebDriver controled Web Browser is getting detected and hence blocking the next requests.

                  WebDriver 控制的Web 浏览器 被检测到并同时被阻止的原因有多种.您可以在以下位置找到一些详细的讨论:

                  There are different reasons for the WebDriver controled Web Browser to get detected and simultaneously get blocked. You can find a couple of detailed discussion in:

                  • recaptcha 3 怎么知道我?m 使用 selenium/chromedriver?
                  • Selenium 和非无头浏览器保持要求验证码

                  这篇关于selenium.common.exceptions.WebDriverException:消息:通过 Python 使用 Selenium 与 ChromeDriver 和 Chrome 的会话 ID 无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:WebDriverException:未知错误:对于旧版本的 Google Chrome,在 Python 中找不到带有 下一篇:错误消息:“chromedriver"可执行文件需要是 PATH

                  相关文章

                • <small id='a2fde'></small><noframes id='a2fde'>

                    1. <tfoot id='a2fde'></tfoot>
                      <legend id='a2fde'><style id='a2fde'><dir id='a2fde'><q id='a2fde'></q></dir></style></legend>

                      <i id='a2fde'><tr id='a2fde'><dt id='a2fde'><q id='a2fde'><span id='a2fde'><b id='a2fde'><form id='a2fde'><ins id='a2fde'></ins><ul id='a2fde'></ul><sub id='a2fde'></sub></form><legend id='a2fde'></legend><bdo id='a2fde'><pre id='a2fde'><center id='a2fde'></center></pre></bdo></b><th id='a2fde'></th></span></q></dt></tr></i><div id='a2fde'><tfoot id='a2fde'></tfoot><dl id='a2fde'><fieldset id='a2fde'></fieldset></dl></div>

                        <bdo id='a2fde'></bdo><ul id='a2fde'></ul>