55
66
77LOGIN_URL = "http://210.38.162.116/default2.aspx"
8+ HEADER = {
9+ 'User-Agent' : 'Mozilla / 5.0(Windows NT 6.1;WOW64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 59.0.3071.115Safari537.36' ,
10+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
11+ 'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' ,
12+ 'Accept-Language' : 'zh-CN,zh;q=0.8'
13+ }
14+
15+
816
917
1018def login (username ,password ):
@@ -13,7 +21,6 @@ def login(username,password):
1321 content = request .text
1422 url = request .url
1523
16-
1724 tree = html .fromstring (content )
1825 viewstate = tree .xpath ("//input[@name='__VIEWSTATE']/@value" )
1926 print (viewstate )
@@ -33,48 +40,35 @@ def login(username,password):
3340 }
3441
3542 # Create header
36- headers = {
37- 'User-Agent' : 'Mozilla / 5.0(Windows NT 6.1;WOW64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 59.0.3071.115Safari537.36' ,
38- 'Content-Type' : 'application/x-www-form-urlencoded' ,
39- 'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' ,
40- 'Accept-Language' : 'zh-CN,zh;q=0.8' ,
41- 'Referer' : url
42- }
43-
43+ HEADER ['Referer' ] = url ;
4444
4545 # Perform login
46- result = requests .post (url , data = payload , headers = headers )
46+ result = requests .post (url , data = payload , headers = HEADER )
4747 tree = html .fromstring (result .text )
48- print (result .text )
4948
5049 xm = list (set (tree .xpath ("//span[@id='xhxm']/text()" )))[0 ]
5150 xm = xm .replace (" " ,"" )
5251 xm = xm [9 :- 2 ]
53- return {'username' :username ,'xm' :xm ,'url' :url }
52+
53+ return result .url
5454 except Exception , e :
5555 return None
5656
57- def loadScorePage (username , xm , url ):
57+ def loadScorePage (url ):
5858 try :
5959 # Scrape url
60- scoreurl = url .replace ("default2" ,"xscjcx" ) + "?xh=" + username + "&xm=" + xm + "&gnmkdm=N121605"
61- headers = {
62- 'User-Agent' : 'Mozilla / 5.0(Windows NT 6.1;WOW64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 59.0.3071.115Safari537.36' ,
63- 'Content-Type' : 'application/x-www-form-urlencoded' ,
64- 'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' ,
65- 'Accept-Language' : 'zh-CN,zh;q=0.8' ,
66- 'Referer' : url
67- }
60+ scoreurl = url .replace ("xs_main" ,"xscjcx" ) + "&gnmkdm=N121605"
61+ HEADER ['Referer' ] = url ;
62+
63+ result = requests .get (scoreurl , headers = HEADER )
6864
69- result = requests .get (scoreurl , headers = headers )
70- # print(result.text)
7165 tree = html .fromstring (result .text )
7266 viewstate = tree .xpath ("//input[@name='__VIEWSTATE']/@value" )
73- return {'viewstate' :viewstate , 'scoreurl ' : scoreurl , 'headers' : headers }
67+ return {'viewstate' :viewstate , 'url ' : scoreurl }
7468 except Exception , e :
7569 return None
7670
77- def loadlncj (viewstate , scoreurl , headers ):
71+ def loadlncj (viewstate , url ):
7872 try :
7973 payload = {
8074 "__EVENTTARGET" : "" ,
@@ -86,7 +80,8 @@ def loadlncj(viewstate, scoreurl, headers):
8680 "ddl_kcxz" : "" ,
8781 "btn_zcj" : "历年成绩" ,
8882 }
89- result = requests .post (scoreurl , data = payload , headers = headers )
83+ HEADER ['Referer' ] = url ;
84+ result = requests .post (url , data = payload ,headers = HEADER )
9085 tree = html .fromstring (result .text )
9186 print (result .text )
9287 datatable = list (set (tree .xpath ("//table[@id='Datagrid1']/tr" )))
0 commit comments