# -*- coding: utf-8 -*- # !/usr/bin/python __author__ = '217小月月坑'
''' 模擬登錄公司OA '''
import urllib2 import urllib import cookielib
auth_url = 'http://192.168.1.251/oa/login.aspx?ReturnUrl=%2fOA%2fdefault.aspx' home_url = 'http://192.168.1.251/OA/default.aspx'; # 登陸用戶名和密碼 data={ '__VIEWSTATE':'/wEPDwUJNjY2NjU0ODQ4ZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAgUMQ2VydENoZWNrQm94BQxJbWFnZUJ1dHRvbjEeyVhXPzgOhtG6MTnQbJYdH20BLw==', '__EVENTVALIDATION':'/wEWBQKq8PPCCgL/vP22BwLMk9PkCQLMg+e+BQLSwpnTCMt3qaBgG108GjrXonLJfARLflBO', 'TextBox_UserName':'huangpeng', 'TextBox_Password':'123', 'passport':'', 'txtSerial':'', 'txtUSBContent':'', 'ImageButton1.x':'59', 'ImageButton1.y':'17', } # urllib進(jìn)行編碼 post_data=urllib.urlencode(data) print post_data # 發(fā)送頭信息 headers ={ "User-Agent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0", "Host":"192.168.1.251", "Referer": "http://192.168.1.251/oa/login.aspx?ReturnUrl=%2fOA%2fdefault.aspx" } # 初始化一個(gè)CookieJar來處理Cookie cookieJar=cookielib.CookieJar() # 實(shí)例化一個(gè)全局opener opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookieJar)) # 獲取cookie req=urllib2.Request(auth_url,post_data,headers) print req result1 = opener.open(req) # 訪問主頁 自動帶著cookie信息 result2 = opener.open(home_url) print cookieJar # 顯示結(jié)果 print result2.read()
|