注释:

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. linux下使用c判断文件夹是否为空的小程序

    自己写了一个 判断文件夹是否为空的小代码 //文件夹操作相关的函数的帮助$: man 3 readdir #include <stdio.h> #include <sys/types ...

  2. 19.Consent视图制作

    新建consentController 继承Controller并引用命名空间 给他一个get的Action Index 添加一个Index的View 新建一个ConsentViewModel 再新建 ...

  3. [翻译]Nativescript 中 Web 视图与 Android/IOS 的双向通信

    English document From http://shripalsoni.com/blog/nativescript-webview-native-bi-directional-communi ...

  4. Linux 程式減肥(strip & objcopy)(转载)

    转自:http://calamaryshop.blogspot.com/2011/11/linux-strip-objcopy.html 對於設計嵌入式Linux系統的研發人員來說,記憶體的空間是非常 ...

  5. 图解SynchronousQueue原理详解-非公平模式

    SynchronousQueue原理详解-非公平模式 开篇 说明:本文分析采用的是jdk1.8 约定:下面内容中Ref-xxx代表的是引用地址,引用对应的节点 前面已经讲解了公平模式的内容,今天来讲解 ...

  6. Kbengine

    Kbengine 编辑 KBEngine是一款开源的游戏服务端引擎,使用简单的约定协议就能够使客户端与服务端进行交互, 使用KBEngine插件能够快速与(Unity3D, OGRE, Cocos2d ...

  7. 汇总:unity中弹道计算和击中移动目标计算方法

    http://download.jikexueyuan.com/detail/id/432.html 弹道计算是游戏里常见的问题,其中关于击中移动目标的自动计算提前量的话题,看似简单,其实还是挺复杂的 ...

  8. GoWeb开发_Iris框架讲解(一)

    Golang介绍 Go语言是谷歌推出的一种全新的编程语言,可以在不损失应用程序性能的情况下降低代码的复杂性.谷歌首席软件工程师罗布派克(Rob Pike)说:我们之所以开发Go,是因为过去10多年间软 ...

  9. W3C标准以及规范

    1.什么是DOCTYPE DOCTYPE是document type(文档类型)的简写,用来说明你用的XHTML或者HTML是什么版本.其中的DTD(例如xhtml1-transitional.dtd ...

  10. C# Func与Action总结

    Action:无参数无返回值委托. Action<T>:泛型委托,无返回值,根据输入参数的个数不同有十六个重载. Func< out T>:无输入参数,有返回值. Func&l ...