我正在尝试使用 python 在我的网站上将移动 gmail 显示到一个 div 中,但问题是我无法像在新选项卡中打开 gmail 那样带来活动的登录会话,只有我可以显示登录屏幕的移动 gmail。有没有办法使用 urllib2 和 coookielib 来实现这一点?这是到目前为止的代码:
import webapp2
import jinja2
import os
import urllib2
import cookielib
class MainHandler(webapp2.RequestHandler):
def get(self):
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
response = opener.open("https://mail.google.com/mail/u/0/x/1dpiqa8pfqv8z-/?f=1")
template_values = {
'content_gmail': unicode(response.read(), encoding='utf-8')
}
template = jinja_environment.get_template('templates/index.html')
self.response.out.write(template.render(template_values))
app = webapp2.WSGIApplication([
('/', MainHandler)
],
debug=True)