Python Simulation Login 4: Access to the library reservation system to see if an appointment is successful

Source: Internet
Author: User
Tags urlencode

The code is intended for easy testing purposes only.

This book Management system is an ASP. ExtJS wrote in the analysis of the page is very complex, once almost give up. But the progress is still slow. I also learned the regular expression by the way. The purpose of this code is to log into the system and get the reservation information. Code a bit messy, later in the collation, here first archive

This URL does not have access to off-campus IP, so the code is for reference only, some logic can be applied

#-*-coding:utf-8-*-#!usr/bin/env pythonimport osimport urllib2import urllibimport cookielibimport refrom BS4 Import Bea Utifulsouplogin_url= ' http://10.21.16.215 ' main_url= ' http://10.21.16.215/Florms/FormSYS.aspx ' seats_url= '/http 10.21.16.215/functionpages/seatbespeak/bespeaksubmitwindow.aspx?parameters= 89b0f70d378f61a7ba0411b5439dbc76521e906832306ce419bccd5f85380be374557d246ee19799e9a8992e242bec3261f078093ce5602b53e9be3dd 0ad5696e85b6beecd6835ba ' username= ' xxxx ' password= ' xxxx ' roomnum= ' 202006 ' def login (): CJ = Cookielib. Cookiejar () opener = Urllib2.build_opener (urllib2. Httpcookieprocessor (CJ)) Urllib2.install_opener (opener) Pre_response=opener.open (Login_url) soup=beautifulsoup (pr E_response.read ()) Div=soup.find (id= ' __eventvalidation ') attr1=dict (div.attrs) [' Value '] #print attr1 div=soup. Find (id= ' __viewstate ') attr2=dict (div.attrs) [' Value '] #print attr2 #login logindata = {' Txtusernam      E ': username, ' txtpassword ':p assword,      ' __eventvalidation ': attr1, ' __viewstate ': attr2, ' cmdok.x ': ' + ', ' cmdok.y ': ' 14 ',     }; Login_req = Urllib2.    Request (Login_url, Urllib.urlencode (Logindata)); 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 "); Login_response=opener.open (login_req) print ' Login success ' Soup=beautifulsoup (Opener.open (Main_url). Read ()) div= Soup.find (id= ' __viewstate ') viewstate=dict (div.attrs) [' Value '] print ' Start get seats info ' room_url= ' http://10.2 1.16.215/functionpages/seatbespeak/seatlayouthandle.ashx ' #datetime =raw_input (' Input your date of TOMORRW ( 2015-01-13): ' Datetime= ' 2015-01-13 ' datetime=datetime+ ' 0:00:00 ' print datetime postdata={' roomnum '            : ' 202006 ', ' Date ':d atetime, ' divtransparenttop ': ' 0 ', ' divtransparentleft ': ' 0 '} headers={      ' X-requested-with ': ' XMLHttpRequest ',      ' Accept-language ': ' ZH-CN ', ' accept-encoding ': ' gzip, deflate ', ' ContentType ': ' application/x- www-form-urlencoded; ', ' Host ': ' 10.21.16.215 ', ' Origin ': ' http://10.21.16.215 ', ' User-agen ' T ': ' mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) gecko/20100101 firefox/14.0.1 ', ' Referer ': ' Http://10.21.16.215/FunctionPages/SeatBespeak/BespeakSe atlayout.aspx?roomid=202006&date=635566176000000000 ', ' Connection ': ' Keep-alive ',} #req = URLLIB2.R    Equest (Room_url, Urllib.urlencode (postdata), headers); #response =opener.open (req) #result =response.read () #print result #get seats seatdata = {' __eventta Rget ': ' Contentpanel1$btnbespeak ', ' __eventargument ': ', ' __viewstate ': '/wepdwulltezmzaxmju4ndfkgaef hl9fq29udhjvbhnszxf1axjlug9zdejhy2tlzxlfxxyebqvgb3jtmgunq29udgvudfbhbmvsmquyq29udgvudfbhbmvsmsridg5czxnwzwfrbrzdb250zw50u Gfuzwwxjgj0bknsb3nlfnml1zniywary7w+39y6xmauzvquuHzhmd7fijhtczy= ', ' __eventvalidation ': '/WEWAGKZ1FTFAGL+MI+WBMMYZMWMY/5C6T+ZSHCAGVWIESBHVAQY5PYRGTQ0ALBK ',            ' Roomopentime ': ' The ' x_changed ': ' false ', ' x_target ': ' Contentpanel1_btnbespeak ', ' form2_collapsed ': ' false ', ' contentpanel1_collapsed ': ' false ', ' X_ajax ': ' True ', # ' X_state ' : ' eyjgb3jtml9jdgwwmf9symxsb29ttmftzsi6eyjuzxh0ijoi5lij5qw85y2v5lq656cu5l+ U5a6kin0sikzvcm0yx2n0bdaxx2xibfnlyxrobyi6eyjuzxh0ijoimzezin0sikzvcm0yx2n0bdayx2xibgjlz2lurgf0zsi6eyjuzxh0ijoimjaxns0xltey     in0sikzvcm0yx2n0bdazx2xibevuzerhdguionsivgv4dci6ijc6mddoh7mxmdowmcj9fq== ',}; headers = {' X-requested-with ': ' XMLHttpRequest ', ' accept-language ': ' ZH-CN ', ' Accept-enc ' Oding ': ' gzip, deflate ', ' ContentType ': ' application/x-www-form-urlencoded; Chartset=utf-8 ', ' Host ': ' 10.21.16.215 ', ' Origin ': ' http://10.21.16.215 ', ' user-agent ': ' mozilla/5.0 (WiNdows NT 6.1; WOW64; rv:14.0) gecko/20100101 firefox/14.0.1 ', ' Referer ': ' Http://10.21.16.215/FunctionPages/SeatBespeak/BespeakSu bmitwindow.aspx?parameters= 89b0f70d378f61a7ba0411b5439dbc76521e906832306ce419bccd5f85380be374557d246ee19799e9a8992e242bec3261f078093ce5602b53e9be3dd 0ad5696e85b6beecd6835ba ', ' Connection ': ' keep-alive '} ' loc=1 while Loc>=0:result=ge T_chair (Seatdata,headers,opener) loc=result.find (' fail ') print ' failed and try ' ' print ' Get your chai    R, Success!!! '        #send Qing Shui he ' postdata={' __eventtarget ': ' form2$ctl00$btnnewdate ', ' __eventargument ': ', ' __viewstate ': '/ Wepdwukltm3mzi4mzg0mmqyaquex19db250cm9sc1jlcxvpcmvqb3n0qmfja0tlev9ffgyfbuzvcm0ybrzgb3jtmirjdgwwmcrkzgxmawjyyxj5brdgb3jtmi rjdgwwmcrkcfn0yxj0rgf0zquwrm9ybtiky3rsmdakynrubmv3zgf0zqumz3jpzfjvb21maxn0bqpxaw5kb3dfzgl05pjodo97fsj4ypsafwutgbwhcfnvi5t Ddl2vul7pih8= ', ' form2$ctl00$ddllibrary ': ' In ', ' F 'Orm2$ctl00$dpstartdate ': ' 2015-01-12 ', ' x_changed ': ' true ', ' Windowedit_hidden ': ' true ', ' x_target ': ' For M2_ctl00_btnnewdate ', ' form2_collapsed ': ' false ', ' gridroomlist_collapsed ': ' false ', ' Gridroomlist_sele Ctedrowindexarray ': ', ' windowedit_collapsed ': ' false ', ' X_ajax ': ' true ', ' x_state ': ' EYJGB3JTML9JDGWWM f9kzgxmawjyyxj5ijp7ikrhdgfuzxh0rmllbgqioijoyw1liiwirgf0yvzhbhvlrmllbgqioijobyisilhfsxrlbxmioltbijaxiiwi5rkz5rkz5qch5yy65z u+5lmm6aagiiwxxsxbijayiiwi5rif5rc05rkz5qch5yy65zu+5lmm6aagiiwxxsxbijaziiwi5zu+ 5lmm6aag5yib5paw5a6e6aqm5a6kiiwxxv0silnlbgvjdgvkvmfsdwuioiiwmij9lcjgb3jtml9jdgwwmf9kcfn0yxj0rgf0zsi6eyjnaw5eyxrlijoimjaxn S0wms0xm1qwmtowndo1ni40oty1kza4ojawiiwivgv4dci6ijiwmtutmdetmtmifswiz3jpzfjvb21maxn0ijp7iljly29yzenvdw50ijozlcjyx1jvd3mion Sivmfsdwvzijpbwyiymdiwmduilclkuozmpbzljzxkurrnojtkv67lrqqilclmuixmsltmsrpmokhljlrlm77kuabppoyilciymiisijiyiiwipgegzxh0onf 0axa9xclpootnuqbml7bpl7tkulrvvjoxmzowmowisdizoju5xcigignsyxnzpvwiec1pdgvTlwrpc2fibgvkxcigzglzywjszwq9xcjkaxnhymxlzfwipjxpbwcgc3jjpvwil0ltywdlcy9py29ul2j1bgxldf9jcm9zcy5wbmdciiagzxh0onf0axa9xclp ootnuqbml7bpl7tkulrvvjoxmzowmowisdizoju5xcigic8+pc9hpijdlfsimjaymda2iiwi5lij5qw85y2v5lq656cu5l+ u5a6kiiwi5rif5rc05rkz5qch5yy65zu+ 5lmm6aagiiwimjqilciyncisijxhigv4ddpxdglwpvwi6ake57qm5pe26ze05li677yamtm6mddlilaymzo1ovwiicbjbgfzcz1cingtaxrlbs1kaxnhymxlz fwiigrpc2fibgvkpvwizglzywjszwrcij48aw1nihnyyz1cii9jbwfnzxmvawnvbi9idwxszxrfy3jvc3mucg5nxcigigv4ddpxdglwpvwi6ake57qm5pe26z e05li677yamtm6mddlilaymzo1ovwiicavpjwvyt4ixsxbijiwmjawnyisiuwbm+alvownles6uueglos/ruwupcisiua4heawtoays+ Agoewmuuwbvus5pummhiisijqilci0iiwipgegzxh0onf0axa9xclpootnuqbml7bpl7tkulrvvjoxmzowmowisdizoju5xcigignsyxnzpvwiec1pdgvtlwr Pc2fibgvkxcigzglzywjszwq9xcjkaxnhymxlzfwipjxpbwcgc3jjpvwil0ltywdlcy9py29ul2j1bgxldf9jcm9zcy5wbmdciiagzxh0onf0axa9xclpootn uqbml7bpl7tkulrvvjoxmzowmowisdizoju5xcigic8+           pc9hpijdxswirgf0yutlexmioltbbnvsbf0sw251bgxdlftudwxsxv0siln0yxrlcyi6w1tdlftdlftdxx19fq== ',} headers={ ' X-requested-with ': ' XMLHttpRequest ', ' accept-language ': ' ZH-CN ', ' accept-encoding ': ' gzip, deflate ', ' ContentType ': ' application/x-www-form-urlencoded; Charset=utf-8 ', ' Host ': ' 10.21.16.215 ', ' Origin ': ' http://10.21.16.215 ', ' user-agent ': ' M ozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) gecko/20100101 firefox/14.0.1 ', ' Referer ': ' Http://10.21.16.215/FunctionPages/SeatBespeak/BespeakSe At.aspx ', ' Connection ': ' Keep-alive ',} req = Urllib2.    Request (' http://10.21.16.215/FunctionPages/SeatBespeak/BespeakSeat.aspx ', Urllib.urlencode (postdata), headers); Response=opener.open (req) result=response.read () Print result # first page headers={# ' x-requested-            With ': ' XMLHttpRequest ', ' accept-language ': ' ZH-CN ', ' accept-encoding ': ' gzip, deflate ', # ' ContentType ': ' application/x-www-form-urlencoded;  Charset=utf-8 ', ' Host ': ' 10.21.16.215 ',          # ' Origin ': ' http://10.21.16.215 ', ' user-agent ': ' mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) gecko/20100101 firefox/14.0.1 ', ' Referer ': ' http://10.21.16.215/Florms/FormSYS.aspx ', ' C Onnection ': ' Keep-alive ',} req = Urllib2.    Request (' http://10.21.16.215/FunctionPages/SeatBespeak/BespeakSeat.aspx ', headers=headers); Response=opener.open (req) result=response.read () #print result #print result "Print Get_log () def Get_cha IR (seatdata,headers,opener): Seat_req = Urllib2.    Request (Seats_url, Urllib.urlencode (seatdata), headers); Seat_response=opener.open (Seat_req) result=seat_response.read () return result#get Chair Logdef get_log (): Url= ' HT    Tp://10.21.16.215/functionpages/readerlog/selectbespeaklog.aspx '; headers={# ' X-requested-with ': ' XMLHttpRequest ', ' accept-language ': ' ZH-CN ', ' Accept-enco ' Ding ': ' gzip, deflate ', # ' ContentType ': ' Application/x-www-form-urlencodeD Charset=utf-8 ', ' Host ': ' 10.21.16.215 ', # ' Origin ': ' http://10.21.16.215 ', ' user-agent ': ' mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) gecko/20100101 firefox/14.0.1 ', ' Referer ': ' http://10.21.16.215/Florms/FormSYS.aspx ', ' C Onnection ': ' Keep-alive ',} req = Urllib2.    Request (url,headers=headers);  Response=urllib2.urlopen (req) result=response.read () #line = ' Three floor single seminar room ', ' 304 ', ' confirmed ', ' 15-01-10 13:00:18 ', ' 15-01-11 08:30:00 "," "," in the ' #print result.find (' third floor single Study room ') #matchObj =re.search (R ' third floor single seminar room (. *?) 08:30:00 ', result, re. M|re. I) #print Matchobj.group (1) p=re.compile (R ' "Three floor single training room" (. *)    08:30:00 ') #print p.findall (Result) [-1] flag=p.findall (result) [ -1].find (' canceled ') if Flag>=0:return True Else:return falseif __name__== ' __main__ ': Login ()


Python Simulation Login 4: Access to the library reservation system to see if an appointment is successful

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.