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

    <small id='KWcMR'></small><noframes id='KWcMR'>

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

    <legend id='KWcMR'><style id='KWcMR'><dir id='KWcMR'><q id='KWcMR'></q></dir></style></legend>

    1. <tfoot id='KWcMR'></tfoot>

      1. Selenium 不使用默认 Chrome 配置文件

        Selenium not using Default Chrome Profile(Selenium 不使用默认 Chrome 配置文件)
          <bdo id='Vt4o4'></bdo><ul id='Vt4o4'></ul>
        • <legend id='Vt4o4'><style id='Vt4o4'><dir id='Vt4o4'><q id='Vt4o4'></q></dir></style></legend>

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

          <small id='Vt4o4'></small><noframes id='Vt4o4'>

          <tfoot id='Vt4o4'></tfoot>

                  本文介绍了Selenium 不使用默认 Chrome 配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Selenium 不会加载我的默认 Chrome 配置文件,我不知道为什么.我已经尝试过配置文件 1 和默认配置文件,但出现相同的错误(如下).我已通过任务管理器确认所有 Chrome 窗口在运行此代码之前都已关闭.有什么想法吗?

                  Selenium will not load my default Chrome Profile and I cannot figure out why. I have tried both Profile 1 and a Default profile with the same error (below). I have confirmed with Task Manager that all Chrome windows are shut down before running this code. Any thoughts?

                  from selenium import webdriver
                  from bs4 import BeautifulSoup
                  import pandas as pd
                  import numpy as np
                  from webdriver_manager.chrome import ChromeDriverManager
                  from selenium.webdriver.chrome.options import Options
                  import os
                  os.system("taskkill /f /im geckodriver.exe /T")
                  os.system("taskkill /f /im chromedriver.exe /T")
                  os.system("taskkill /f /im IEDriverServer.exe /T")
                  os.system("taskkill /f /im chrome.exe /T")
                  
                  driver2 = r"C:Usersxxx.wdmdriverschromedriver87.0.4280.20win32chromedriver.exe"
                  options = webdriver.ChromeOptions() 
                  options.add_argument("user-data-dir=C:\Usersxxx\AppData\Local\Google\Chrome\User Data\Profile 1")
                  driver = webdriver.Chrome(executable_path=driver2, chrome_options=options)
                  driver.get("https://www.google.co.in")
                  
                  

                  Traceback (most recent call last):
                    File "C:UsersxxxOneDrivePythonpyReportRun.py", line 16, in <module>
                      driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
                    File "C:Python38libsite-packagesseleniumwebdriverchromewebdriver.py", line 76, in __init__
                      RemoteWebDriver.__init__(
                    File "C:Python38libsite-packagesseleniumwebdriver
                  emotewebdriver.py", line 157, in __init__
                      self.start_session(capabilities, browser_profile)
                    File "C:Python38libsite-packagesseleniumwebdriver
                  emotewebdriver.py", line 252, in start_session
                      response = self.execute(Command.NEW_SESSION, parameters)
                    File "C:Python38libsite-packagesseleniumwebdriver
                  emotewebdriver.py", line 321, in execute
                      self.error_handler.check_response(response)
                    File "C:Python38libsite-packagesseleniumwebdriver
                  emoteerrorhandler.py", line 242, in check_response
                      raise exception_class(message, screen, stacktrace)
                  selenium.common.exceptions.WebDriverException: Message: unknown error: Could not remove old devtools port file. Perhaps the given user-data-dir at C:UsersxxxAppDataLocalGoogleChromeUser DataProfile 1 is still attached to a running Chrome or Chromium process
                  

                  推荐答案

                  chrom_options.add_argument("user-data-dir=C:\Users
                  obert.car\AppData\Local\Google\Chrome\User Data")
                  
                  chrom_options.add_argument("profile-directory=Profile 1")
                  

                  user-data-dir 将 profile 视为默认值,您不必指定它.如果是其他东西,则通过 profile-directory 参数指定它

                  user-data-dir considers profile as default , and you don't have to specify that . If its something else specify it through profile-directory argument

                  创建个人资料的步骤:

                  打开:地址栏中的 chrome://version

                  open : chrome://version in address bar

                  复制用户目录文件夹完全到例如c: mp ewdir

                  copy the user dir folder completely to eg c: mp ewdir

                  打开复制的用户数据 (newdir) 并搜索名为 Default 的文件夹.这是个人资料文件夹.

                  open the copied user data (newdir) and search for folder called Default . This is the profile folder.

                  重命名默认文件夹为Profile 1"

                  rename the Default folder as "Profile 1"

                  现在使用这个:

                  chrom_options.add_argument("user-data-dir=c:\tmp\newdir")
                  
                  chrom_options.add_argument("profile-directory=Profile 1")
                  

                  这篇关于Selenium 不使用默认 Chrome 配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)

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

                        <small id='Kjg5s'></small><noframes id='Kjg5s'>

                        • <tfoot id='Kjg5s'></tfoot>

                            <legend id='Kjg5s'><style id='Kjg5s'><dir id='Kjg5s'><q id='Kjg5s'></q></dir></style></legend>