Reputation: 727
Before I start: I have already seen Log into Google account using Python? but I dont feel that it fully adresses my problem.
Ok, I didn't know how to best well word my anwser because the problem is actually quite complicated...
Scenario:
I am developing a python application, and at one stage it has to very quickly attempt to login to google using urllib. It wouldn't be too hard to submit the form just normally, but the (very likely) issue arises that if they user has already logged in to google on this computer, then instead of the normal text boxes they see, they get the little form they can click on to choose their account. I will show you what I mean.
Instead I want to be sure what appears will be the normal login page:
Possible Solutions: (how would I implement these) 1) When requesting the site, have some sort of "icongito mode" like you see in web browsers. If you launch in Icongito Mode, then the google does not show the accounts you are already logged in to. 2) Via a proxy, but then google may flag as suspicious.
So, this post was quite long, but if someone can give me a solution then it would be great. To wrap up: I want to access google via Python to log in, but I don't want google to show existing accounts.
EDIT: Example Code:
from bs4 import BeautifulSoup
import requests
form_data={'Email': '****@gmail..com', 'Passwd': '******'}
post = "https://accounts.google.com/"
with requests.Session() as s:
data = BeautifulSoup(s.get("https://mail.google.com").text)
for inp in data.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
Upvotes: 1
Views: 1688
Reputation: 1724
[UPDATE] If you haven't found it yet, I highly recommend you look at this:
I'd suggest first spending some time digging through their own API documentation:
It would help to answer your question with some idea of the platform you are running this on. I suspect you aren't running into a problem with the machine having logged in before, but simply that you aren't clearing cookies from previous logins.
Upvotes: 1