Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium webdriver.get()方法未打开指定的URL_Python_Selenium_Selenium Webdriver - Fatal编程技术网

Python Selenium webdriver.get()方法未打开指定的URL

Python Selenium webdriver.get()方法未打开指定的URL,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,我正在尝试使用chromedriver.exe进行一些web抓取/自动化操作——我的代码如下 from selenium import webdriver browser = webdriver.Chrome('MY_PATH') browser.get("https://www.google.com") browser.close() 执行“browser”变量后,会打开一个空白的google浏览器,但当我尝试执行.get()函数时,我收到的错误是: WebDriver

我正在尝试使用chromedriver.exe进行一些web抓取/自动化操作——我的代码如下

from selenium import webdriver 
browser = webdriver.Chrome('MY_PATH')
browser.get("https://www.google.com")
browser.close()
执行“browser”变量后,会打开一个空白的google浏览器,但当我尝试执行.get()函数时,我收到的错误是:

WebDriverException                        Traceback (most recent call last)
<ipython-input-36-0ba0932650bf> in <module>
----> 1 browser.get("https://www.google.com")
      2 browser.close()

~\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in get(self, url)
    331         Loads a web page in the current browser session.
    332         """
--> 333         self.execute(Command.GET, {'url': url})
    334 
    335     @property

~\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params)
    319         response = self.command_executor.execute(driver_command, params)
    320         if response:
--> 321             self.error_handler.check_response(response)
    322             response['value'] = self._unwrap_value(
    323                 response.get('value', None))

~\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response)
    240                 alert_text = value['alert'].get('text')
    241             raise exception_class(message, screen, stacktrace, alert_text)
--> 242         raise exception_class(message, screen, stacktrace)
    243 
    244     def _value_or_default(self, obj, key, default):

WebDriverException: Message: chrome not reachable
  (Session info: chrome=85.0.4183.102)
WebDriverException回溯(最近一次调用)
在里面
---->1.获取(“https://www.google.com")
2.close()浏览器
get中的~\Anaconda3\lib\site packages\selenium\webdriver\remote\webdriver.py(self,url)
331在当前浏览器会话中加载网页。
332         """
-->333 self.execute(Command.GET,{'url':url})
334
335@property
执行中的~\Anaconda3\lib\site packages\selenium\webdriver\remote\webdriver.py(self,driver\u命令,参数)
319 response=self.command\u executor.execute(driver\u command,params)
320如果响应:
-->321自我错误处理程序检查响应(响应)
322响应['value']=self.\u展开值(
323响应。获取('值',无))
检查响应中的~\Anaconda3\lib\site packages\selenium\webdriver\remote\errorhandler.py(self,response)
240警报文本=值['alert']。获取('text')
241引发异常类(消息、屏幕、堆栈跟踪、警报文本)
-->242引发异常类(消息、屏幕、堆栈跟踪)
243
244定义值或默认值(self、obj、key、default):
WebDriverException:消息:无法访问chrome
(会话信息:chrome=85.0.4183.102)

如果您有任何想法/反馈/建议,我们将不胜感激!

ChromeDriver和Chrome浏览器不兼容,也许您可能有最新的Chrome浏览器,但您没有最新的ChromeDriver-您可以下载它-它是ChromeDriver 86.0.4240.22

,因此我认为问题不在于您的代码,我认为问题在于我这是你提到“我的路径”的那一行,对我来说,最有效的方法是指定chromedriver.exe应用程序本身的路径

browser = webdriver.Chrome("C:\Program Files (x86)\chromedriver.exe")
这对我来说非常好,也为我打开了chrome的大门。 如果您没有chromedriver应用程序,可以在此处下载

首先,确保以下几点:

  • 确保“路径”环境变量中存在chromedriver
  • 检查您的chromedriver版本是否与您正在使用的chrome版本匹配
    -您可以从关于Google chrome的帮助-->中查看您的chrome版本
    • 然后从下载兼容的Chromedriver版本

  • 这是由于您使用的特定chrome版本的chrome驱动程序错误造成的。 你可以在这里找到镀铬器 或者您可以让webdriver manager通过执行以下操作来处理所有问题:

    pip install webdriver-manager in command prompt
    
    而不是简单地使用

    from webdriver_manager.chrome import ChromeDriverManager
    driver = webdriver.Chrome(ChromeDriverManager().install())
    
    试试这个

    • 记住将路径传递给
      可执行文件路径
      关键字参数
    • 拥有与Chrome和Chrome驱动程序相匹配的版本
    
    从selenium导入webdriver
    chrome\u driver\u path='/home/aahnik/Downloads/apps/chromedriver'
    #安装chrome驱动程序可执行文件的路径。
    #确保有匹配版本的Chrome和Chrome驱动程序
    driver=webdriver.Chrome(可执行文件路径=Chrome\u驱动程序路径)
    驱动程序。获取(“https://aahnik.github.io/")
    
    再次交叉检查ChromeDriver版本和Chrome版本。