问题
Hey friends. I want to open Gmail but with a particular account. My python script has a list of gmail accounts and i want the one to open in gmail which has been clicked/selected. I tried using the credentials in the URL but am not happy with that as I don't want to put the users password in the URL + it doesn't work :).
I'm using webbrowser.open(URL) to open gmail.
Solution?
回答1:
I have no clue if this would work, but it may be worth a shot.
You could try to spoof the browser and login via urllib and grab the cookie. Then you could programatically put the cookie in the browsers cookie directory and launch the browser to gmail.
It seems like it would work if you can get the browser+google to believe the cookie is a valid one, but it may be possible.
回答2:
Is there any reason why you're not using IMAP to interact with the Gmail account?
import imaplib
M=imaplib.IMAP4_SSL('imap.gmail.com', 993)
M.login('myemailaddress@gmail.com','password')
# do things!
M.close()
M.logout()
来源:https://stackoverflow.com/questions/3211105/python-webbrowser-and-gmail