我是网络编程的新手,但为了它,我尝试不使用标准代码而是作为 python 应用程序登录到 google 帐户,但这是不可能的 有没有人试过这个?谁能帮忙?
最佳答案
我制作了一个处理谷歌登录的 python 类,它能够获取任何需要用户登录的谷歌服务页面:
class SessionGoogle:
def __init__(self, url_login, url_auth, login, pwd):
self.ses = requests.session()
login_html = self.ses.get(url_login)
soup_login = BeautifulSoup(login_html.content).find('form').find_all('input')
my_dict = {}
for u in soup_login:
if u.has_attr('value'):
my_dict[u['name']] = u['value']
# override the inputs without login and pwd:
my_dict['Email'] = login
my_dict['Passwd'] = pwd
self.ses.post(url_auth, data=my_dict)
def get(self, URL):
return self.ses.get(URL).text
想法是转到登录页面 GALX 隐藏输入值并将其发送回 google + 登录名和密码。它需要模块 requests
和 beautifulSoup
使用示例:
url_login = "https://accounts.google.com/ServiceLogin"
url_auth = "https://accounts.google.com/ServiceLoginAuth"
session = SessionGoogle(url_login, url_auth, "myGoogleLogin", "myPassword")
print session.get("http://plus.google.com")
希望对你有帮助
关于python - 使用python登录谷歌?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6754709/