1 #-*- coding: utf-8 -*-
2 #!usr/bin/env python
3 importos4 importurllib25 importurllib6 importcookielib7 importre8 from bs4 importBeautifulSoup9
10 Login_URL='http://xxxx'
11 Main_URL='http://xxxx/Florms/FormSYS.aspx'
12 username='XXXXX'
13 password='XXX'
14 roomNum='20200xxxx'
15 roomId=['309','310','311','307',]16 day='2015-XXXX'
17 deflogin():18 Seats_URL='http://10.21.16.215/FunctionPages/SeatBespeak/BespeakSubmitWindow.aspx?parameters='
19 cj =cookielib.CookieJar()20 opener =urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))21 urllib2.install_opener(opener)22 pre_response=opener.open(Login_URL)23 soup=BeautifulSoup(pre_response.read())24 div=soup.find(id='__EVENTVALIDATION')25 attr1=dict(div.attrs)['value']26 #print attr1
27 div=soup.find(id='__VIEWSTATE')28 attr2=dict(div.attrs)['value']29 #print attr2
30 #login
31 LoginData ={32 'txtUserName':username,33 'txtPassword':password,34 '__EVENTVALIDATION':attr1,35 '__VIEWSTATE':attr2,36 'cmdOK.x':'40',37 'cmdOK.y':'14',38 };39 login_req =urllib2.Request(Login_URL, urllib.urlencode(LoginData));40 login_req.add_header('User-Agent', "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36");41 login_response=opener.open(login_req)42 print 'login success'
43 #get chairinfo
44 while search_seats(day)==False:45 print 'system is not running , waitting'
46 while get_start(Seats_URL,opener)==False:47 print 'try again'
48 print 'Success and enjoy'
49 defget_start(Seats_URL,opener):50 total_chair_args=''
51 i=0;52 while total_chair_args=='' and i
58 if total_chair_args=='':59 print 'All seats has been ordered'
60 returnFalse61 else:62 Seats_URL=Seats_URL+total_chair_args63 print 'starting get seats order info'
64 #get order args by header
65 headers={66 #'X-Requested-With': 'XMLHttpReq