使用python登录到Google吗? [英] Logging in to google using python?
问题描述
我对网络编程尚不陌生,但出于此原因,我尝试不使用标准代码而是使用python应用程序登录google帐户,但这是不可能的 有人尝试过吗?有人可以帮忙吗?
I am fairly new to web programing but for the sake of it, I am trying to login to google account not using standard code but as a python application, but it is impossible to do so has anyone tried to this before? can anyone help?
推荐答案
我制作了一个python类,用于处理Google登录,并且能够获取要求用户登录的任何Google服务页面:
I made a python class that handle google login and the is able to get any google service page that requires the user to be logged in:
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
The idea is to go to the login page GALX hidden input value and send it back to google + login and password. It requires modules requests
and 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登录到Google吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!