python 3.3 웹 시 뮬 레이 션 로그 인

2123 단어 Python
python 3.3 웹 시 뮬 레이 션 로그 인
인 용 된 다른 사람의 코드
 
# -*- coding: UTF-8 -*-
#-------------------------------------------------------------------------------
# Name:          2
# Purpose:
#
# Author:      lenovo
#
# Created:     06/09/2013
# Copyright:   (c) lenovo 2013
# Licence:     
#-------------------------------------------------------------------------------
#coding=utf-8
import re
import urllib
import urllib.request
import urllib.request
import http.cookiejar
import re
class xiaobai:
    post_data=b""#       
    def __init__(self):
        '''    ,   cookies '''
        cj = http.cookiejar.CookieJar()
        opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
        opener.addheaders = [('User-agent', 'Opera/9.23')]
        urllib.request.install_opener(opener)

    def login(self,loginurl,bianma):
        '''    '''
        req = urllib.request.Request(loginurl,self.post_data)
        _response = urllib.request.urlopen(req)
        _d=_response.read()
        _d =_d.decode(bianma)
        return _d

    def getpagehtml(self,pageurl,bianma):
        '''             html  '''
        req2=urllib.request.Request(pageurl)
        _response2=urllib.request.urlopen(req2)
        _d2=_response2.read()
        _d22 = _d2.decode(bianma)
        return _d2
if __name__=="__main__":
        x=xiaobai()
        #    post  
        x.post_data=urllib.parse.urlencode({'uname':'usernamexxxx','password':'pwdxxxx','op':'login','xoops_redirect':'/user.php'}).encode(encoding='UTF8')
        #print('x.post_data:',urllib.parse.parse_qs(x.post_data))
        y=x.login("http://www.lvye.org/user.php","utf-8")#  
        #       html   
        #print (x.getpagehtml("http://www.lvye.org/userinfo.php?uid=404071","utf-8"))
        print (x.getpagehtml("http://www.lvye.org","cp720"))

 
 

좋은 웹페이지 즐겨찾기