Python, Webbrowser and Gmail

家住魔仙堡 提交于 2021-02-11 14:30:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!