python - 使用python登录谷歌?

标签 python authentication

我是网络编程的新手,但为了它,我尝试不使用标准代码而是作为 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 + 登录名和密码。它需要模块 requestsbeautifulSoup

使用示例:

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/

相关文章:

Python 3.5.1 - 将变量分配给目标文件夹内的所有文件(文件类型 : . jpg)

python - 如何在 GAE 的搜索 API 中实现自定义拼写检查

python - 在 pandas 中格式化包含两行的表格

iphone - 在现有应用程序上构建登录

android - Android : GoogleAuthIOException 中的端点错误

python - 修改列表中的一个对象会修改列表中的所有对象

python - 有没有办法让这段代码在计算机上的负担更少?

javascript - Angular http : how to call images with custom headers?

web-services - Symfony2 自定义认证 : user logged but not authenticated

authentication - 使用 XMLHttpRequest 的用户身份验证适用于 IE,而不适用于 Chrome?