Skip to content
Snippets Groups Projects
Unverified Commit 80496bbc authored by Recolic Keghart's avatar Recolic Keghart
Browse files

init

parents
No related branches found
No related tags found
No related merge requests found
# 华科公选自动选课
我是在补选阶段使用的这个工具。它包含一个简陋的python脚本用来自动监视-自动抢课,和一个fish script脚本用来多线程启动python脚本(一般不必要)。和一个极其简陋的fish script用来在交易时爆破单个课程。
### 自动监视
进入选课页面,选择按课堂选课,拿下你请求`*.action`用的cookie,填进python的cookie_str。
将你不想要的类别和你不想要的课,填进python的blacklist.
直接启动python脚本,它自动监视,自动给你选上。你也可以使用go.fish。阅读go.fish来了解它做了什么和如何使用。
### 交易时对单个课程的爆破
这部分无需脚本。我只是3分钟简单写了一下。
在交易之前,chrome或chromium浏览器F12,监视network。然后点击那个课程的选课。在出现的请求里面右键那个到*.action的post请求,选copy -> copy as curl。然后替换`fuck_one_course.fish`的第7行。别忘了在后面加上 `> $log_fname`
然后暴力开多进程。看输出log的速度稳定之后,让卖家退课。
```
for i in (seq 128)
./fuck_one_course.fish &
end
```
这时候脚本会瞬间爆炸。我不想修,反正你的课选上了。杀死它们,打游戏去。
### note
我不想维护这个脚本。它价值不大,仅供偶尔使用。
#!/usr/bin/fish
#
set log_fname (mktemp)
function fuck
curl -s 'http://wsxk.hust.edu.cn/zxqstudentcourse/zxqcoursesresult.action' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Origin: http://wsxk.hust.edu.cn' -H 'Upgrade-Insecure-Requests: 1' -H 'DNT: 1' -H 'Content-Type: application/x-www-form-urlencoded' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Referer: http://wsxk.hust.edu.cn/zxqstudentcourse/coursesandclassroom.action?markZB=6&ggkdl=&GGKDLBH=0&skZC=&skJC=&kcmc=%E6%98%93%E7%BB%8F' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.9' -H 'Cookie: _gscu_1399484133=45466154wop59714; BIGipServerpool6_http=352979466.20480.0000; JSESSIONID=00001gprsedNAbzR0_9x_Dgce72:190ld4dfl' --data 'kcbh=1438094&kczxf=2&ktbh=201821438094001&ktrl=200&ktrs=200&markZB=6&kcmc=%E6%98%93%E7%BB%8F%E4%B8%8E%E4%B8%AD%E5%9B%BD%E6%96%87%E5%8C%96' --compressed > $log_fname
if grep '选课失败,课堂人数已满!' $log_fname
echo 'Failed.'$log_fname
else
echo 'Success.'$log_fname
cat $log_fname > succ.$log_fname.log
end
end
while true
fuck
end
go.fish 0 → 100755
#!/usr/bin/fish
# usage: ./go.fish threads > shit.log
for i in (seq $argv[1])
python -u hust_wsxk.py $i &
end
for j in (jobs -p)
if [ $j = 'Process' ]
continue
end
wait $j
end
## enable debug
#import http.client as http_client
#import logging
#http_client.HTTPConnection.debuglevel = 1
## You must initialize logging, otherwise you'll not see debug output.
#logging.basicConfig()
#logging.getLogger().setLevel(logging.DEBUG)
#requests_log = logging.getLogger("requests.packages.urllib3")
#requests_log.setLevel(logging.DEBUG)
#requests_log.propagate = True
FORCE_FUCK = False # Only try to select course if there's a seat.
blacklist = ['自然科学类','艺术类','中级俄语']
cookie_str = '_gscu_1399484133=45466154wop59714; BIGipServerpool6_http=352979466.20480.0000; JSESSIONID=00001gprsedNAbzR0_9x_Dgce72:190ld4dfl'
##################################################################################
import requests
import sys
try:
MY_MAGIC = sys.argv[1]
except:
MY_MAGIC = 0
MAGIC_HEAD = '[{}] '.format(MY_MAGIC)
cookie = {}
for c in cookie_str.split('; '):
cookie[c.split('=')[0]] = c.split('=')[1]
def fetch_course_page(pageNo):
wsxk_get_url = 'http://wsxk.hust.edu.cn/zxqstudentcourse/coursesandclassroom.action?markZB=6&page=' + str(pageNo)
resp = requests.get(wsxk_get_url, cookies=cookie)
if resp.status_code != 200:
raise RuntimeError("resp.status code not 200. ")
cont = resp.text
return cont
from bs4 import BeautifulSoup
def parse_page_html(cont):
parsed = BeautifulSoup(cont, features='lxml')
mainlist = parsed.body.find_all('tr', attrs={'class':'tablelist'})
#print(mainlist)
return mainlist
def check_and_fuck_a_course(cont):
global succ,tried,checked
for keyword in blacklist:
if str(cont).find(keyword) != -1:
return
checked += 1
shit = str(cont.find('input'))
# <input disabled="" id="201821434234001" onclick="selectKT(this.id,'200','200','大学生健康教育','1434234','2');" type="button" value="选课"/>
id_index_beg = shit.find('id="') + 4
id_index_end = shit.find('"', id_index_beg) - 1
my_id = shit[id_index_beg : id_index_end+1]
#print(my_id,id_index_beg,id_index_end)
assert(len(my_id) == len("201821434234001"))
shit = shit.replace('this.id', my_id)
arg_list_beg = shit.find('(') + 1
arg_list_end = shit.find(')')
arg_list = shit[arg_list_beg:arg_list_end]
ktbh,ktrl,ktrs,kcmcl,kczxf,kcbh = arg_list.replace('\'','').split(',')
if ktrl == ktrs:
# class full
if not FORCE_FUCK:
return
if not FORCE_FUCK:
print(MAGIC_HEAD, 'FIRE!!!', shit)
tried += 1
data_dict = {
'ktbh':ktbh,
'ktrl':ktrl,
'ktrs':ktrs,
'kcmc1':kcmcl,
'kczxf':kczxf,
'kcbh':kcbh,
'markZB':'6'
}
data2 = 'ktbh={}&ktrl={}&ktrs={}&kcmc1={}&kczxf={}&kcbh={}&markZB=6'.format(ktbh,ktrl,ktrs,kcmcl,kczxf,kcbh).encode('utf-8')
post_url = 'http://wsxk.hust.edu.cn/zxqstudentcourse/zxqcoursesresult.action'
resp = requests.post(post_url, data=data_dict, cookies=cookie)
if resp.status_code != 200:
print(MAGIC_HEAD, 'err: post resp code not 200')
return
if resp.text.count('选课失败,课堂人数已满') != 0:
print(MAGIC_HEAD, 'fuck. course is full. course info:', data_dict)
else:
print(MAGIC_HEAD, 'good!', shit, ',checked=', checked, '\n', resp.text)
succ += 1
print(MAGIC_HEAD, data_dict)
with open('save-' + str(checked) + '.log', 'w+') as f:
f.write(shit)
f.write(resp.text)
checked = 0
succ = 0
tried = 0
while True:
for pageNo in range(34):
try:
fetched = fetch_course_page(pageNo+1)
except:
continue
ls = parse_page_html(fetched)
if ls == []:
print(MAGIC_HEAD, 'Warning: empty class list')
try:
for course in ls:
check_and_fuck_a_course(course)
except:
continue
print(MAGIC_HEAD, 'checked', checked, 'courses. succ', succ, ',tried', tried, file=sys.stderr)
print(MAGIC_HEAD, 'new round!')
<input id="20182w102517002" onclick="selectKT(20182w102517002,'150','149','孙子兵法与人生智慧','w102517','2');" type="button" value="选课"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>选课提示信息</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF_8" />
<link href="/css/base_eng.css" rel="stylesheet" type="text/css">
</head>
<body class="bodymain">
<div class="divmsg mtop15 wid98b">
<div class="divmsgtitle">
<b>选课结果</b></div>
<div class="divmsgtxt">
<ul>
<li>
您已成功选择课程:。
</li>
<li>系统已将您已选课程的相关信息发送到您的邮箱,请注意查收。</li>
<li>如果您需要换成其他课程请先退选后再重新选择。</li>
</ul>
<div class="ptop15 pbom5">
<input type="button" value="查看已选课程" onClick="location='/zxqstudentcourse/zxqalreadycourse.action';"
style="width: 100px" />
<input type="button" value="继续选课" onClick="location='/zxqstudentcourse/zxqremian.action';" style="width:80px" />
</div>
</div>
</div>
</body>
</html>
<input disabled="" id="20182w106191002" onclick="selectKT(20182w106191002,'180','181','中华礼仪与风俗','w106191','2');" type="button" value="选课"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>选课提示信息</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF_8" />
<link href="/css/base_eng.css" rel="stylesheet" type="text/css">
</head>
<body class="bodymain">
<div class="divmsg mtop15 wid98b">
<div class="divmsgtitle">
<b>选课结果</b></div>
<div class="divmsgtxt">
<ul>
<li>
本学期公选课已选两门,如需选择请先退选!
</li>
</ul>
<div class="ptop15 pbom5">
<input type="button" value="查看已选课程" onClick="location='/zxqstudentcourse/zxqalreadycourse.action';"
style="width: 100px" />
<input type="button" value="继续选课" onClick="location='/zxqstudentcourse/zxqremian.action';" style="width:80px" />
</div>
</div>
</div>
</body>
</html>
<input disabled="" id="20182w102517001" onclick="selectKT(20182w102517001,'150','152','孙子兵法与人生智慧','w102517','2');" type="button" value="选课"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>选课提示信息</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF_8" />
<link href="/css/base_eng.css" rel="stylesheet" type="text/css">
</head>
<body class="bodymain">
<div class="divmsg mtop15 wid98b">
<div class="divmsgtitle">
<b>选课结果</b></div>
<div class="divmsgtxt">
<ul>
<li>
本学期公选课已选两门,如需选择请先退选!
</li>
</ul>
<div class="ptop15 pbom5">
<input type="button" value="查看已选课程" onClick="location='/zxqstudentcourse/zxqalreadycourse.action';"
style="width: 100px" />
<input type="button" value="继续选课" onClick="location='/zxqstudentcourse/zxqremian.action';" style="width:80px" />
</div>
</div>
</div>
</body>
</html>
<input disabled="" id="20182w106191002" onclick="selectKT(20182w106191002,'180','181','中华礼仪与风俗','w106191','2');" type="button" value="选课"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>选课提示信息</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF_8" />
<link href="/css/base_eng.css" rel="stylesheet" type="text/css">
</head>
<body class="bodymain">
<div class="divmsg mtop15 wid98b">
<div class="divmsgtitle">
<b>选课结果</b></div>
<div class="divmsgtxt">
<ul>
<li>
本学期公选课已选两门,如需选择请先退选!
</li>
</ul>
<div class="ptop15 pbom5">
<input type="button" value="查看已选课程" onClick="location='/zxqstudentcourse/zxqalreadycourse.action';"
style="width: 100px" />
<input type="button" value="继续选课" onClick="location='/zxqstudentcourse/zxqremian.action';" style="width:80px" />
</div>
</div>
</div>
</body>
</html>
<input disabled="" id="20182w102517001" onclick="selectKT(20182w102517001,'150','152','孙子兵法与人生智慧','w102517','2');" type="button" value="选课"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>选课提示信息</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF_8" />
<link href="/css/base_eng.css" rel="stylesheet" type="text/css">
</head>
<body class="bodymain">
<div class="divmsg mtop15 wid98b">
<div class="divmsgtitle">
<b>选课结果</b></div>
<div class="divmsgtxt">
<ul>
<li>
本学期公选课已选两门,如需选择请先退选!
</li>
</ul>
<div class="ptop15 pbom5">
<input type="button" value="查看已选课程" onClick="location='/zxqstudentcourse/zxqalreadycourse.action';"
style="width: 100px" />
<input type="button" value="继续选课" onClick="location='/zxqstudentcourse/zxqremian.action';" style="width:80px" />
</div>
</div>
</div>
</body>
</html>
<input disabled="" id="20182w106191002" onclick="selectKT(20182w106191002,'180','181','中华礼仪与风俗','w106191','2');" type="button" value="选课"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>选课提示信息</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF_8" />
<link href="/css/base_eng.css" rel="stylesheet" type="text/css">
</head>
<body class="bodymain">
<div class="divmsg mtop15 wid98b">
<div class="divmsgtitle">
<b>选课结果</b></div>
<div class="divmsgtxt">
<ul>
<li>
本学期公选课已选两门,如需选择请先退选!
</li>
</ul>
<div class="ptop15 pbom5">
<input type="button" value="查看已选课程" onClick="location='/zxqstudentcourse/zxqalreadycourse.action';"
style="width: 100px" />
<input type="button" value="继续选课" onClick="location='/zxqstudentcourse/zxqremian.action';" style="width:80px" />
</div>
</div>
</div>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment