python图书馆预约系统_【转载】Python实现图书馆预约功能

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值