无法使用 Chrome 个人资料登录

问题描述 投票:0回答:1

我正在尝试使用 Chrome 配置文件自动登录 Facebook 或任何其他凭据网站。但由于某种原因,我无法登录该网站。

我先分享一下代码,

    def setup():
        try:
            log.info("setting profile")
            driver, action = setupWebdriver(profile_path="/home/name/.config/google-chrome",profile_name="Profile 12")
            time.sleep(5)
            driver.get("https://www.facebook.com/")
           
        except Exception as e:
            log.error(e)
        return driver,action


def setupWebdriver(profile_path=None,profile_name=None):
    '''Set up Selenium Webdriver'''
    
    chrome_options = Options()
    if profile_path is not None:
        chrome_options.add_argument(f'--user-data-dir={profile_path}')
        chrome_options.add_argument(f"profile-directory={profile_name}")
        chrome_options.add_argument("--start-maximized")
        # chrome_options.add_argument("--headless") #For AWS/GCP
        driver=webdriver.Chrome(options=chrome_options)#, executable_path=r"C:\Users\agney\Desktop\chromedriver-win32\chromedriver.exe")
       
        driver.maximize_window()
        action = ActionChains(driver)
    else:
        chrome_options.add_argument("--headless") #For AWS/GCP/
        chrome_options.add_argument("enable-automation")
        chrome_options.add_argument("--window-size=1920,1080")
        chrome_options.add_argument("--start-maximized")
        chrome_options.add_argument("--no-sandbox")
        chrome_options.add_argument("--disable-extensions")
        chrome_options.add_argument("--dns-prefetch-disable")
        chrome_options.add_argument("--disable-gpu")
        driver=webdriver.Chrome(options=chrome_options)#, executable_path=r"C:\Users\agney\Desktop\chromedriver-win32\chromedriver.exe")
        driver.delete_all_cookies()
        driver.maximize_window()
        action = ActionChains(driver)
    return driver,action

当我运行它时,我可以使用该帐户打开Chrome浏览器,如下图所示。您可以在右上角看到个人资料名称“fb”。

enter image description here

但是当我尝试通过它登录 Facebook 以外的其他网站时,它就是无法登录。我在 Selenium 打开的浏览器中检查保存的密码,没有密码,但是当我通过手动打开相同的配置文件并检查保存的信用来执行相同操作时,它们在浏览器中已保存。

我已经检查了路径和所有内容,它们都是正确的。

浏览器版本:120.0.6099.216

python selenium-webdriver automation
1个回答
0
投票

所以,我分析了问题的根本原因,这只是源于我使用的配置文件。如果有人尝试使用 Chrome 的特定配置文件:

  • 使用该特定配置文件打开浏览器。
  • 在地址栏中输入 chrome://version。
  • 使用浏览器响应中指定的路径,如 如下图所示。

enter image description here

如果您尝试使用最初在另一台计算机上创建的配置文件,我建议您查看此链接:将 Google Chrome 配置文件传输到另一台计算机。

传输 Chrome 配置文件时,不会包含已保存的凭据。要解决此问题,您可以首先通过输入密码和电子邮件来手动自动登录。完成后,下次运行自动化时,您将能够登录该网站。

© www.soinside.com 2019 - 2024. All rights reserved.