-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpc.py
More file actions
51 lines (43 loc) · 1.72 KB
/
pc.py
File metadata and controls
51 lines (43 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /usr/bin/env python
#coding:utf-8
import sys
import re
import urllib2
import urllib
import requests
import cookielib
## 这段代码是用于解决中文报错的问题
reload(sys)
sys.setdefaultencoding("utf8")
#####################################################
#登录人人
loginurl = 'http://ids.xidian.edu.cn/authserver/login?service=http%3A%2F%2Fjwxt.xidian.edu.cn%2Fcaslogin.jsp'
logindomain = 'http://ids.xidian.edu.cn'
class Login(object):
def __init__(self):
self.name = ''
self.passwprd = ''
self.domain = ''
self.cj = cookielib.LWPCookieJar()
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))
urllib2.install_opener(self.opener)
def setLoginInfo(self,username,password,domain):
'''''设置用户登录信息'''
self.name = username
self.pwd = password
# self.domain = domain
def login(self):
'''''登录网站'''
loginparams = {'username':self.name, 'password':self.pwd}
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/48.0.2564.82 Chrome/48.0.2564.82 Safari/537.36'}
req = urllib2.Request(loginurl, urllib.urlencode(loginparams),headers=headers)
response = urllib2.urlopen(req)
self.operate = self.opener.open(req)
thePage = response.read()
if __name__ == '__main__':
userlogin = Login()
username = '14030130101'
password = '193036'
domain = logindomain
userlogin.setLoginInfo(username,password,domain)
userlogin.login()