Python Gmail自动登录脚本

时间:2018-08-12 02:19:04

标签: python selenium selenium-webdriver login 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)

0 个答案:

没有答案