Chrome 如何编辑我的代码,使谷歌不检测我时,我是无头?

gmxoilav  于 2022-12-28  发布在  Go
关注(0)|答案(1)|浏览(264)

我有代码,以及与selenuim工作。但当我尝试使用无头选项。它检测到我。什么方式谷歌检测到我。代码用来登录到我的谷歌帐户。
我尝试添加用户代理并设置窗口大小,但没有任何效果

# import required modules
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service

# Enter your email address and password between the quotations mark
mail_address = 'my email'
password = 'password'

# Create chrome instance
opt = Options()

# Disable google from detected the bot
opt.add_argument('--disable-blink-features=AutomationControlled')

# Maximize the browser
opt.add_argument('--start-maximized')

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=opt)

# Open the login Page
driver.get('https://accounts.google.com/ServiceLogin?hl=en&passive=true&continue=https://www.google.com/&ec=GAZAAQ')

# Enter the email address
driver.find_element(By.ID, "identifierId").send_keys(mail_address)

# click Next
driver.find_element(By.ID, "identifierNext").click()

# Wait for 10 seconds
driver.implicitly_wait(10)

driver.find_element(
        By.XPATH, '//*[@id="password"]/div[1]/div/div[1]/input').send_keys(password)
# Wait for 10 seconds
driver.implicitly_wait(10)

# Click next
driver.find_element(By.ID, "passwordNext").click()

# wait for 2 seconds
driver.implicitly_wait(8)

我为headless添加的行

options.add_argument('--headless')
options.add_argument('--no-sandbox')
ylamdve6

ylamdve61#

它与使用undetected_chromedriver一起工作

相关问题