Posts Tagged ‘renren’

2010/01/19

其实 Python 中一般都是直接用 urllib.urlopen() 来抓取网页内容或者模拟登陆等操作,但是 GAE 出于安全考虑不可以用 urlopen 操作,取而代之的就是 urlfetch.fetch()。fetch() 函数、参数(via):

fetch(url, payload=None, method=GET, headers={}, allow_truncated=False, follow_redirects=True, deadline=None)

Python语言: GAE urlfetch登录人人
01 def login_renren(self):
02     login_url = ‘http://passport.renren.com/PLogin.do’
03     login_data = urllib.urlencode(
04         {
05          ‘domain’:‘renren.com’,
06          ‘email’:  renren_username,
07          ‘password’: renren_passwd,
08          ‘origURL’:‘http://home.renren.com/Home.do’,
09          })
10     result = urlfetch.fetch(
11         url = login_url,
12         payload = login_data,
13         method = urlfetch.POST,
14         headers = {‘Cookie’:make_cookie_header(cookie),
15                    ‘Content-Type’:‘application/x-www-form-urlencoded’,
16                    ‘User-Agent’:‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6′ },
17         follow_redirects = False)

继续学习 GAE。

Related posts

Tags: ,,,.