注释:

1,原博主是:http://blog.csdn.net/cq361106306/article/details/42644001#

2,学校是我现在的学校,我最近也在研究这个,所以转了。

3,请勿长期使用,容易黑名单。(反正我手动抢也能抢一堆)

4,仅供学习交流,侵删。

 #-*- coding: utf-8 -*-
#!usr/bin/env python
import os
import urllib2
import urllib
import cookielib
import re
from bs4 import BeautifulSoup Login_URL='http://xxxx'
Main_URL='http://xxxx/Florms/FormSYS.aspx'
username='XXXXX'
password='XXX'
roomNum='20200xxxx'
roomId=['','','','',]
day='2015-XXXX'
def login():
Seats_URL='http://10.21.16.215/FunctionPages/SeatBespeak/BespeakSubmitWindow.aspx?parameters='
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
pre_response=opener.open(Login_URL)
soup=BeautifulSoup(pre_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 = {
'txtUserName':username,
'txtPassword':password,
'__EVENTVALIDATION':attr1,
'__VIEWSTATE':attr2,
'cmdOK.x':'',
'cmdOK.y':'',
};
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'
#get chairinfo
while search_seats(day)==False:
print 'system is not running , waitting '
while get_start(Seats_URL,opener)==False:
print 'try again'
print 'Success and enjoy'
def get_start(Seats_URL,opener):
total_chair_args=''
i=0;
while total_chair_args=='' and i<len(roomId):
total_chair_args=get_chair_info(roomId[i])
print 'start try roomid of '+roomId[i]
if total_chair_args=='':
print roomId[i]+' has been ordered\n';
i=i+1
if total_chair_args=='':
print 'All seats has been ordered'
return False
else:
Seats_URL=Seats_URL+total_chair_args
print 'starting get seats order info'
#get order args by header
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/FunctionPages/SeatBespeak/BespeakSeatLayout.aspx?roomId='+roomNum,
'Connection' : 'Keep-Alive',
}
req = urllib2.Request(Seats_URL,headers=headers);
response=urllib2.urlopen(req)
result=response.read()
#print result
#get order info
soup=BeautifulSoup(result)
div=soup.find(id='__EVENTVALIDATION')
attr1=dict(div.attrs)['value']
#print attr1
div=soup.find(id='__VIEWSTATE')
attr2=dict(div.attrs)['value']
#print attr2
#get Seats
SeatData = {
'__EVENTTARGET':'ContentPanel1$btnBespeak',
'__EVENTARGUMENT':' ',
'__VIEWSTATE':attr2,
'__EVENTVALIDATION':attr1,
'roomOpenTime':'8:30',
'X_CHANGED':'false',
'X_TARGET':'ContentPanel1_btnBespeak',
'Form2_Collapsed':'false',
'ContentPanel1_Collapsed':'false',
'X_AJAX':'true',
#'X_STATE':'eyJGb3JtMl9jdGwwMF9sYmxSb29tTmFtZSI6eyJUZXh0Ijoi5LiJ5qW85Y2V5Lq656CU5L+u5a6kIn0sIkZvcm0yX2N0bDAxX2xibFNlYXRObyI6eyJUZXh0IjoiMzEzIn0sIkZvcm0yX2N0bDAyX2xibGJlZ2luRGF0ZSI6eyJUZXh0IjoiMjAxNS0xLTEyIn0sIkZvcm0yX2N0bDAzX2xibEVuZERhdGUiOnsiVGV4dCI6Ijc6MDDoh7MxMDowMCJ9fQ==',
};
headers = {
'X-Requested-With': 'XMLHttpRequest',
'Accept-Language': 'zh-cn',
'Accept-Encoding': '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' :Seats_URL ,
'Connection' : 'Keep-Alive'
}
result=get_chair_order(SeatData,headers,opener,Seats_URL)
if result.find('失败')>=0 or get_log()==False:
return False
else:
return True
#search seats
def search_seats(datetime):
postdata={
'__EVENTTARGET':'Form2$ctl00$btnnewdate',
'__EVENTARGUMENT':' ',
'__VIEWSTATE':'/wEPDwUKLTM3MzI4Mzg0MmQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgYFBUZvcm0yBRZGb3JtMiRjdGwwMCRkZGxMaWJyYXJ5BRdGb3JtMiRjdGwwMCRkcFN0YXJ0RGF0ZQUWRm9ybTIkY3RsMDAkYnRubmV3ZGF0ZQUMZ3JpZFJvb21MaXN0BQpXaW5kb3dFZGl05pJoDo97fsj4YPsAfwutGBWhcfnVi5TdDL2VUl7PIH8=',
'Form2$ctl00$ddlLibrary':'',
'Form2$ctl00$dpStartDate':datetime,
'X_CHANGED':'true',
'WindowEdit_Hidden':'true',
'X_TARGET':'Form2_ctl00_btnnewdate',
'Form2_Collapsed':'false',
'gridRoomList_Collapsed':'false',
'gridRoomList_SelectedRowIndexArray':' ',
'WindowEdit_Collapsed':'false',
'X_AJAX':'true',
'X_STATE':'eyJGb3JtMl9jdGwwMF9kZGxMaWJyYXJ5Ijp7IkRhdGFUZXh0RmllbGQiOiJOYW1lIiwiRGF0YVZhbHVlRmllbGQiOiJObyIsIlhfSXRlbXMiOltbIjAxIiwi5rKZ5rKz5qCh5Yy65Zu+5Lmm6aaGIiwxXSxbIjAyIiwi5riF5rC05rKz5qCh5Yy65Zu+5Lmm6aaGIiwxXSxbIjAzIiwi5Zu+5Lmm6aaG5Yib5paw5a6e6aqM5a6kIiwxXV0sIlNlbGVjdGVkVmFsdWUiOiIwMiJ9LCJGb3JtMl9jdGwwMF9kcFN0YXJ0RGF0ZSI6eyJNaW5EYXRlIjoiMjAxNS0wMS0xM1QwMTow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YWdlcy9pY29uL2J1bGxldF9jcm9zcy5wbmdcIiAgZXh0OnF0aXA9XCLpooTnuqbml7bpl7TkuLrvvJoxMzowMOWIsDIzOjU5XCIgIC8+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' : '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/BespeakSeat.aspx',
'Connection' : 'Keep-Alive',
}
req = urllib2.Request('http://10.21.16.215/FunctionPages/SeatBespeak/BespeakSeat.aspx', urllib.urlencode(postdata),headers);
response=urllib2.urlopen(req)
result=response.read()
if result.find('zoom.png')>=0:
return True
else:
return False
#out=open('tt.html','w')
#out.write(result)
#get chair location args
def get_chair_info(roomId_):
print 'start get seats info'
room_url='http://10.21.16.215/FunctionPages/SeatBespeak/SeatLayoutHandle.ashx'
#datetime=raw_input('input your date of tomorrw(2015-01-13): ')
datetime=day
datetime=datetime+' 0:00:00'
print datetime
postdata={
'roomNum':roomNum,
'date':datetime,
'divTransparentTop':'',
'divTransparentLeft':''
}
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-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/BespeakSeatLayout.aspx?roomId='+roomNum,
'Connection' : 'Keep-Alive',
}
req = urllib2.Request(room_url, urllib.urlencode(postdata),headers);
response=urllib2.urlopen(req)
result=response.read()
out=open('info.html','w')
out.write(result)
soup=BeautifulSoup(result)
#roomId
div=soup.find(id=roomNum+roomId_)
chair_info=dict(div.attrs)['onclick']
#print chair_info
matchObj=re.search( r'BespeakSeatClick(.∗?)', chair_info, re.M|re.I)
chair_args=matchObj.group(1)[1:-1]
#print chair_args
return chair_args
#print result
#get order
def get_chair_order(SeatData,headers,opener,Seats_URL):
seat_req = urllib2.Request(Seats_URL, urllib.urlencode(SeatData),headers);
seat_response=opener.open(seat_req)
result=seat_response.read()
return result
#get chair log
def get_log():
url='http://10.21.16.215/FunctionPages/ReaderLog/SelectBespeakLog.aspx';
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',
'Connection' : 'Keep-Alive',
}
req = urllib2.Request(url,headers=headers);
response=urllib2.urlopen(req)
result=response.read()
#line = '三楼单人研修室", "304", "已确认", "15-01-10 13:00:18", "15-01-11 08:30:00", "", "在'
#print result.find('三楼单人研修室')
#matchObj=re.search( r'三楼单人研修室(.*?)08:30:00', result, re.M|re.I)
#print matchObj.group(1)
p=re.compile(r'"三楼单人研修室"(.*?)08:30:00')
#print p.findall(result)[-1]
flag=p.findall(result)[-1].find('已取消')
if flag>=0:
return False
else:
return True if __name__=='__main__':
login()

【转载】Python实现图书馆预约功能的更多相关文章

  1. Atitit php java python nodejs错误日志功能的比较

    Atitit php  java  python  nodejs错误日志功能的比较 1.1. Php方案 自带 1 1.2. Java解决方案 SLF4J 1 1.3. Python解决方案 自带lo ...

  2. [转载] Python数据类型知识点全解

    [转载] Python数据类型知识点全解 1.字符串 字符串常用功能 name = 'derek' print(name.capitalize()) #首字母大写 Derek print(name.c ...

  3. JSP+SSM+Mysql实现的图书馆预约占座管理系统

    项目简介 项目来源于:https://gitee.com/gepanjiang/LibrarySeats 因原gitee仓库无数据库文件且存在水印,经过本人修改,现将该仓库重新上传至个人gitee仓库 ...

  4. [转载] Python的GIL是什么鬼,多线程性能究竟如何

    原文: http://cenalulu.github.io/python/gil-in-python/ GIL是什么 首先需要明确的一点是GIL并不是Python的特性,它是在实现Python解析器( ...

  5. Python实现进度条功能

    Python实现进度条功能 import sys, time def progress(percent, width=50): # 设置进度条的宽度 if percent >= 100: # 当 ...

  6. [转载]Python 包管理工具

    [转载]Python 包管理工具 最近由于机缘巧合,使用各种方法安装了一些Python包,所以对Python的包管理开始感兴趣.在网上找到一篇很好的文章:https://blog.zengrong.n ...

  7. 转载-python学习笔记之输入输出功能读取和写入数据

    读取.写入和 Python 在 “探索 Python” 系列以前的文章中,学习了基本的 Python 数据类型和一些容器数据类型,例如tuple.string 和 list.其他文章讨论了 Pytho ...

  8. 【转载】用Python实现端口映射功能(A/B/C内外网)

    转载地址 :http://hutaow.com/blog/2014/09/08/write-tcp-mapping-program-with-python/ 有A,B,C三台计算机,A,B互通,B,C ...

  9. 转载-python学习笔记之文件I/O

    Python 文件I/O 本章只讲述所有基本的的I/O函数,更多函数请参考Python标准文档. 打印到屏幕 最简单的输出方法是用print语句,你可以给它传递零个或多个用逗号隔开的表达式.此函数把你 ...

随机推荐

  1. App Distribution Guide--(三)---Configuring Your Xcode Project for Distribution

    Configuring Your Xcode Project for Distribution You can edit your project settings anytime, but some ...

  2. jQuery 操作select 下拉列表

    jQuery这个框架方便了我们对于HTML元素的操作,本来以为自己对于Select操作也算是熟悉了,但上午在测试的时候才发现自己了解的还真不多. 看了一下jQuery的一些方法后,理出了一些常用的方法 ...

  3. Noip2016day1 天天爱跑步running

    题目描述 小c同学认为跑步非常有趣,于是决定制作一款叫做<天天爱跑步>的游戏.«天天爱跑步»是一个养成类游戏,需要玩家每天按时上线,完成打卡任务. 这个游戏的地图可以看作一一棵包含 个结点 ...

  4. gitlab之source tree使用方法

    一.简介 1.source tree 是什么 可视化项目版本控制软件,使用git项目管理,支持windows/mac 客户端使用source tree开发源码,图形化提交到gitlab 二.使用sou ...

  5. js new Date("2016-07-01 08:00:00") 格式在IE内核浏览器中显示NaN的问题

    js new Date("2016-07-01 08:00:00") 格式在IE内核浏览器中显示NaN的问题 废话就不多了,var dd = new Date("2016 ...

  6. Centos 7 install cacti监控

    首先,先安装LNMP服务 安装一: 如果觉得安装起来麻烦,可以到如下网站进行安装: https://lnmp.org/install.html 安装二: 采用yum或者安装包的方式进行安装,具体操作请 ...

  7. C# 字符串string

    一.引言 在 C# 中,字符串是System.String类的一个引用类型.但与其他引用类型不同的是,C#将字符串视为一个基本类型,它可以申请为一个常量,也可以直接给它赋值. string关键字是Sy ...

  8. loj6198谢特 后缀数组+并查集+Trie

    先把问题放在后缀数组上考虑 已知两个数组a b,求min(a[i],...,a[j])+(b[i]^b[j])的最大值 套路题 初始每个点都是一个小连通块 把a按从大到小的顺序加入,计算当前加入边作为 ...

  9. Net Core WebApi几种版本控制对比

    Net Core WebApi几种版本控制对比 一.版本控制的好处: (1)有助于及时推出功能, 而不会破坏现有系统. (2)它还可以帮助为选定的客户提供额外的功能. API 版本控制可以采用不同的方 ...

  10. NetCore1.1+Linux

    NetCore1.1+Linux部署初体验   1.环境准备 Centaos7+Win10 虚拟机 Win10安装VS2017 https://www.asp.net/downloads注意勾选下.N ...