使用Python登录Google帐户来进入网站 [英] Enter website by logging in Google Account using Python

查看:321
本文介绍了使用Python登录Google帐户来进入网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个网站,该网站以图表的形式显示群体人数(来自www.codecamy.com).

I am making a website that makes graphs of the number of people present in groups (from www.codecamy.com).

为此,我制定了一个计划.

To achieve this I came with a plan.

我将拥有一个服务器,该服务器将轮询CodeCademy组页面( http://www.codecademy.com/groups ),每30秒从HTML检索所需的信息.

I will have a server which will poll the CodeCademy groups page (http://www.codecademy.com/groups) every 30 seconds and retrieve the needed information from that HTML.

然后,当客户端连接到我的网站时,服务器将向客户端提供该信息,然后客户端将使用 http://www.jqplot.com /根据该信息绘制图形.

Then, when a client connects to my website, the server will give the client that information and then the client will use either http://www.chartjs.org/docs/ or http://www.jqplot.com/ to draw the graph based on that information.

但是,这是一个大问题.如果您单击了CodeCademy中的任何链接,那么您意识到您需要拥有一个帐户才能实际看到该网站.这可以是一个Facebook帐户,一个Google帐户或一个Twitter帐户.

However, there is a big problem. If you have clicked any of the links from CodeCademy, then you realized you need to have an account to actually see the website. This can be a facebook account, a google account or a twitter account.

简而言之,如果我想访问包含有关组的信息的页面,则需要为我的服务器拥有一个Bot帐户,并且需要教我的服务器登录该帐户.

So, short story, if I want to access the page with the information about the groups, I need to have a Bot account for my server and I need to teach my server to login into that account.

因此,我在gmail上创建了一个名为codecademybot的虚拟帐户,我希望我的服务器使用该帐户登录codecademy,以便它可以看到该页面的内容.

Thus, I have created a dummy account at gmail, called codecademybot, and I want my server to use this account to login into codecademy so it can see that page's content.

按照 quickstart python教程(将我连接到google +的链接),我现在也有了与之交互的代码.

By following a quickstart python tutorial that connects me to google+ I now also have the code to interact with it.

尽管如此,我仍然对如何与网站交互还没有最小的想法.我有以下问题:

However, despite all this, I still don't have the smallest idea on how to interact with the website. I have the following questions:

  1. 如何检测我是否已登录自己的google帐户?
  2. 如何将自己连接到该帐户,以便随后可以访问该页面?
  3. 登录该网站是否有特殊链接?

我很迷茫,不胜感激.

推荐答案

不要让所有代码示例和操作方法误入歧途.它们旨在用于更复杂的情况.

Don't let all the code samples and howto's lead you astray. They are intended for more complicated cases.

  • 这不是oauth2授权,而是oauth2身份验证
  • 您不是具有clientID和机密信息的客户端. Codecademy是具有clientID和密码的客户端.您的codecademybot帐户就是用户.

这意味着您仅需要自动化普通用户登录codecademy时的操作即可.在浏览器中,使用侦听开发工具(例如IE开发工具,FireBug等)来进行几次交互,并查看HTTP请求的会话情况.

This means that you only need to automate what ordinary users do when logging into codecademy. Play that interaction that in the browser a couple times with a dev tool listening in (IE dev tool, FireBug, whatever) and look at the conversation of HTTP requests.

这是您想要模仿的.

据我所见

  • Conversation starts by sending a request to http://codecademy.com/auth/google_oauth2.
  • The request gets forwarded to a https url at google
  • If I've previously logged in at google, a couple cookies get sent along and I get authenticated. The request gets sent back to the codecademy redirect_url at http://www.codecademy.com/auth/google_oauth2/callback with the oauth2 authentication code as a parameter.
  • Supposedly codecademy and google chat, for this takes about three seconds.
  • They agree that I'm me and two cookies (remember_user_token and _session_id) get set in my browser before I get forwarded to http://www.codecademy.com/

我认为最后一点很有趣.您如何使用浏览器手动登录,收听对话并将这两个Cookie复制到您的自动代码中呢?查看它们是否足以用作身份验证令牌,并允许您从网站中获取数据.

That last bit, I think, is interesting. How about you manually log in using your browser, listen in on the conversation and copy these two cookies to your automated code. See if they suffice as authentication tokens and allow you to fetch the data from the website.

如果没有,那么我热烈推荐@ CrisBee21的答案.希望pyCurl可以很好地模拟浏览器,以便为您进行对话.

If not, then I warmly recommend @CrisBee21 s answer. Let's hope pyCurl can emulate the browser well enough to do the conversation for you.

还有一件事情,当我浏览该站点时,我看到一个REST api请求,即 http://www.codecademy.com/api/v1/notifications/ 用户ID /unread_count?authentication_token = 某些令牌

One more thing, when I browse around the site, I see one REST api request, namely http://www.codecademy.com/api/v1/notifications/userid/unread_count?authentication_token=some token

浏览到 http://www.codecademy.com/api/v1/users/ 用户ID /?authentication_token = 令牌 给我更多有关自己的信息

Surfing to http://www.codecademy.com/api/v1/users/userid/?authentication_token=the token gives me more info about myself

http://www.codecademy.com/api/v1/users/ userid /groups?authentication_token = 令牌给了我所在的组.

http://www.codecademy.com/api/v1/users/userid/groups?authentication_token=the token gives me the groups I'm in.

如果您有关于codecademy REST api的更多文档,可以尝试从那里获取.我找不到任何文档,正在整理中.

If you have more documentation about the codecademy REST api, you could try and take it from there. I couldn't find any documentation, am making this up as I go along.

这篇关于使用Python登录Google帐户来进入网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆