在多个登录页面上,需要谷歌登录才能继续。我想用requests
python 中的库以便让我自己登录。通常这很容易使用requests
库,但是我无法让它工作。我不确定这是否是由于 Google 做出的一些限制(也许我需要使用他们的 API?),或者是否是因为 Google 登录页面要求用户先输入他们的电子邮件,然后按提交,然后输入他们的密码等
这个问题之前已经在这里被问过,但没有一个解决方案对我有用。目前我一直在使用此解决方案中提供的代码:使用Python登录Google帐户? https://stackoverflow.com/questions/39540479/log-into-google-account-using-python如图所示:
from bs4 import BeautifulSoup
import requests
my_email = "[email protected] /cdn-cgi/l/email-protection" # my email is here
my_pass = "my_password" # my password is here
form_data={'Email': my_email, 'Passwd': my_pass}
post = "https://accounts.google.com/signin/challenge/sl/password"
with requests.Session() as s:
soup = BeautifulSoup(s.get("https://mail.google.com").text, "html.parser")
for inp in soup.select("#gaia_loginform input[name]"):
if inp["name"] not in form_data:
form_data[inp["name"]] = inp["value"]
s.post(post, form_data)
html = s.get("https://mail.google.com/mail/u/0/#inbox").content
print(my_email in s.get('https://mail.google.com/mail/u/0/#inbox').text) # Prints 'False', should print 'True'
正如你所看到的,最后返回的代码False
。此外,如果我将 html 写入文件并在浏览器中打开它,我得到的页面是默认的 Google 登录页面,表明它不起作用。
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)