使用 AWS Lambda 函数在 Google 上自动登录

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

我想使用 AWS Lambda 函数自动登录 Google,但遇到了困难。如果有人可以帮助我解决这些问题,我将不胜感激:

1°) 在 AWS Lambda 上部署 unDetected-chromedriver:在熟悉框架并在本地成功运行代码后,我无法将其部署在 Lambda 函数中。我没有找到有关如何操作的信息。这将是我的第一选择。

2°)作为第 1 点的替代方案,我尝试将 Selenium 与 --user-data-dir 标志一起使用。添加此驱动程序选项时,我的脚本失败,并收到以下错误:

消息:会话未创建:Chrome 无法启动:正常退出。 (会话未创建:DevToolsActivePort 文件不存在)

下面是我的代码:

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' : "[email protected]",
    '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)

解决这些问题的任何帮助或指导对我来说都非常有价值。预先感谢您提供的任何帮助!

selenium-webdriver aws-lambda selenium-chromedriver
1个回答
0
投票

您可以在 lambda 函数中使用 google api 密钥..您可以在 google 控制台中获取此密钥

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