zoukankan      html  css  js  c++  java
  • python模拟登录人人网

    参考:

    http://www.cnblogs.com/txw1958/archive/2012/03/12/2392067.html

    http://www.cnblogs.com/chenyg32/archive/2013/06/04/3116317.html

    http://docs.python.org/2/howto/urllib2.html

    http://stackoverflow.com/questions/189555/how-to-use-python-to-login-to-a-webpage-and-retrieve-cookies-for-later-usage

     1 import urllib,urllib2,cookielib
     2 from BeautifulSoup import BeautifulSoup
     3 url='http://www.renren.com/SysHome.do'
     4 resp1=urllib2.urlopen(url)
     5 source=resp1.read()
     6 soup1=BeautifulSoup(source)
     7 user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
     8 headers = { 'User-Agent' : user_agent}
     9 params={'domain':'renren.com','origURL':'http://www.renren.com/indexcon','email':'*********@****.com','password':'******'}
    10 params=urllib.urlencode(params)
    11 params=params.encode('ISO-8859-1')
    12 cj=cookielib.CookieJar()
    13 opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    14 urllib2.install_opener(opener)
    15 resp2=urllib2.Request('http://www.renren.com/PLogin.do',params,headers)
    16 response = urllib2.urlopen(resp2)
    17 # print opener.open(resp2)
    18 the_page=response.read()
    19 print the_page
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    【iOS】打印方法名
    【iOS】设备系统版本
    【iOS】receiver type *** for instance message is a forward declaration
    【iOS】获取应用程序本地路径
    hash算法
    redis文档
    Couchbase
    nodejs多核处理
    基于nodejs的消息中心
    nodejs两个例子
  • 原文地址:https://www.cnblogs.com/yuliyang/p/3540171.html
Copyright © 2011-2022 走看看