You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:在AWS Lambda中实现Google自动登录的两类技术问题

在AWS Lambda实现Google自动登录的问题求助

我尝试用AWS Lambda函数实现Google自动登录,遇到两个瓶颈,求解决:

1. AWS Lambda部署undetected-chromedriver

我熟悉这个框架,本地代码运行正常,但不知道怎么部署到Lambda函数里,这是我的首选方案。

2. 替代方案:带--user-data-dir参数的Selenium脚本失败

添加该驱动选项后脚本报错,错误信息:

Message: session not created: Chrome failed to start: exited normally.
(session not created: DevToolsActivePort file doesn't exist)

我的代码如下:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.support import expected_conditions as EC

# Credenciales
platform_cred = {
    'user' : "my-mail@gmail.com",
    'password' : "password1234"
}


# Obtener credenciales
user = platform_cred['user']
password = platform_cred['password']

try:
    #Página de login
    url_login =  'https://accounts.google.com/v3/signin/identifier?continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ifkv=ARZ0qKKlHmWPmUjrIyhEKyPF-fVgRf_dT_ACqQpf14q_v8u9SLNqLyt4n8q5vlR6qNka2j1kEVNiIA&rip=1&sacu=1&service=mail&flowName=GlifWebSignIn&flowEntry=ServiceLogin&dsh=S-1459547155%3A1711711347417853&theme=mn&ddm=0'

    # Opciones de navegación
    options = Options()
    service = webdriver.ChromeService("C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe")
    options.binary_location = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'
    options.add_argument('--start-maximized')
    options.add_argument('--disable-extensions')
    
    options.add_argument("--user-data-dir=C:\\Users\\Jose A\\AppData\\Local\\Google\\Chrome\\User Data")
    options.add_argument('profile-directory=Profile 3')

    # Driver
    driver = webdriver.Chrome(options=options, service=service)

    driver.get(url_login)

    # Login to account.google.com

    element = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR, '#identifierId')))
    element.send_keys(user)
    
    # Pulsamos el boton "Ver todos los envíos"
    element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="identifierNext"]/div/button/span')))
    element.click()
    
    element_password = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="password"]/div[1]/div/div[1]/input')))
    element_password.send_keys(password)

    element_next = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="passwordNext"]/div/button/span')))
    element_next.click()
    
except WebDriverException as e:
    print(e)

求任何解决这两个问题的建议或指导,感谢!

内容的提问来源于stack exchange,提问作者ejooroo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 22:08:33