Abd*_*oud 9 python selenium automation selenium-chromedriver selenium-webdriver
我尝试使用 Gmail 或任何 Google 服务登录,但它显示以下“此浏览器或应用程序可能不安全”消息:

我也尝试过在我的 acc 中启用安全性较低的应用程序等选项,但它没有用。然后我创建了一个新的谷歌帐户,它对我有用。但不是我的旧acc。
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
browser = webdriver.Chrome()
browser.get('https://accounts.google.com/servicelogin')
search_form = browser.find_element_by_id("identifierId")
search_form.send_keys('mygmail')
nextButton = browser.find_elements_by_xpath('//*[@id ="identifierNext"]')
search_form.send_keys('password')
nextButton[0].click()
Run Code Online (Sandbox Code Playgroud)
首先不要使用chrome和chromedriver。您需要使用 Firefox。(如果未安装)下载并安装 Firefox。使用普通 Firefox 登录 Google。
您需要向 Google 网站表明您不是机器人。你可以使用这样的代码:
from selenium import webdriver
import geckodriver_autoinstaller
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
geckodriver_autoinstaller.install()
profile = webdriver.FirefoxProfile(
'/Users/<user name>/Library/Application Support/Firefox/Profiles/xxxxx.default-release')
profile.set_preference("dom.webdriver.enabled", False)
profile.set_preference('useAutomationExtension', False)
profile.update_preferences()
desired = DesiredCapabilities.FIREFOX
driver = webdriver.Firefox(firefox_profile=profile,
desired_capabilities=desired)
Run Code Online (Sandbox Code Playgroud)
这可以帮助您找到您的个人资料位置。
实际上只有一个原因,chromedriver 是由 Google 编码的。他们可以很容易地理解它是否是机器人。但是当我们用 Firefox 添加用户数据时,他们无法理解是否有机器人。
你可以这样欺骗谷歌。它也对我有用。我非常努力地做到这一点。希望它也能在你身上得到解决。
这对我有用。我从 GitHub 上找到了解决方案。
from selenium import webdriver
from selenium_stealth import stealth
options = webdriver.ChromeOptions()
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('--disable-blink-features=AutomationControlled')
driver = webdriver.Chrome(options=options)
stealth(driver,
languages=["en-US", "en"],
vendor="Google Inc.",
platform="Win32",
webgl_vendor="Intel Inc.",
renderer="Intel Iris OpenGL Engine",
fix_hairline=True,
)
driver.get("https://www.google.com")
Run Code Online (Sandbox Code Playgroud)
您可以使用以下方法轻松绕过谷歌机器人检测undetected_chromedriver:
pip install undetected-chromedriver
pip install selenium
Run Code Online (Sandbox Code Playgroud)
学分:https://github.com/xtekky/google-login-bypass/blob/main/login.py
import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class Main:
def __init_(self) -> None:
self.url = 'https://accounts.google.com/ServiceLogin'
self.driver = driver = uc.Chrome(use_subprocess=True)
self.time = 10
def login(self, email, password):
# edit: fixed missing end-quotes on below lines
WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.NAME, 'identifier'))).send_keys(f'{email}\n')
WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.NAME, 'password'))).send_keys(f'{password}\n')
self.code()
def code(self):
# [ ---------- paste your code here ---------- ]
time.sleep(self.time)
if __name__ == "__main__":
# ---------- EDIT ----------
email = 'email' # replace email
password = 'password' # replace password
# ---------- EDIT ----------
driver = Main()
driver.login(email, password)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5039 次 |
| 最近记录: |