首页 > 解决方案 > Python Gmail 自动登录脚本

问题描述

我正在尝试编写一个简单的 Python 脚本来登录 Gmail(我知道我可能违反了 Gmail 条款和条件,但这仅用于测试目的)。在在这里发布这个问题之前,我已经对其进行了适当的研究。但是,它仍然不起作用。我在 YouTube 上观看了一个视频,并且相同的代码在那里工作,但在我的本地机器上没有(我在我的 HP 笔记本电脑上使用 Windows 10)。

你能看看下面的脚本,如果有任何错误,请告诉我?

from selenium import webdriver
import time


driver = webdriver.Chrome(r'C:\Users\hp\Downloads\chromedriver.exe')
driver.get('https://accounts.google.com/signin/v2/identifier?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin')

email_field = driver.find_element_by_id('identifierId')
email_field.clear()
email_field.send_keys('My Email ID')

email_field_button = driver.find_element_by_id('identifierNext')
email_field_button.click()
time.sleep(1)


password_field = driver.find_element_by_id('password')
password_field.clear()
password_field.send_keys('My password')

password_field_button = driver.find_element_by_id('passwordNext')
password_field_button.click()
time.sleep(1)

这是我收到的错误消息:

Traceback (most recent call last):
  File "gmail_login.py", line 6, in <module>
    driver.get('https://accounts.google.com/signin/v2/identifier?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin')
  File "C:\Users\hp\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 332, in get
[6012:9752:0812/071242.870:ERROR:shader_disk_cache.cc(237)] Failed to create shader cache entry: -2
[6012:9752:0812/071242.962:ERROR:shader_disk_cache.cc(237)] Failed to create shader cache entry: -2
    self.execute(Command.GET, {'url': url})
  File "C:\Users\hp\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot determine loading status
from unknown error: missing or invalid 'entry.level'
  (Session info: chrome=68.0.3440.106)
  (Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.17134 x86_64)

标签: pythonseleniumselenium-webdriverlogingmail

解决方案


推荐阅读