上传文件至 /
This commit is contained in:
commit
158cbad0a9
272
main.py
Normal file
272
main.py
Normal file
@ -0,0 +1,272 @@
|
|||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
def read_jsessionid_from_file(filename):
|
||||||
|
"""从指定文件中读取JSESSIONID"""
|
||||||
|
try:
|
||||||
|
with open(filename, 'r') as file:
|
||||||
|
jsessionid = file.read().strip() # 去除可能存在的多余空白字符
|
||||||
|
return jsessionid
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(f"未能找到文件: {filename}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
# 在主程序开始的地方读取JSESSIONID
|
||||||
|
jsessionid_filename = 'jsessionid.txt' # 确保这个文件名与实际存放JSESSIONID的文件名一致
|
||||||
|
jsessionid = read_jsessionid_from_file(jsessionid_filename)
|
||||||
|
def get_xkkz_id_and_sessionUserKey():
|
||||||
|
# 请求头信息,根据提供的信息设置
|
||||||
|
headers = {
|
||||||
|
'Host': 'jwpd.jsei.edu.cn',
|
||||||
|
'Connection': 'keep-alive',
|
||||||
|
'Cache-Control': 'max-age=0',
|
||||||
|
'sec-ch-ua': '"Chromium";v="134", "Not:A-Brand";v="24", "Microsoft Edge";v="134"',
|
||||||
|
'sec-ch-ua-mobile': '?0',
|
||||||
|
'sec-ch-ua-platform': '"Windows"',
|
||||||
|
'Upgrade-Insecure-Requests': '1',
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0',
|
||||||
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
||||||
|
'Sec-Fetch-Site': 'none',
|
||||||
|
'Sec-Fetch-Mode': 'navigate',
|
||||||
|
'Sec-Fetch-User': '?1',
|
||||||
|
'Sec-Fetch-Dest': 'document',
|
||||||
|
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
||||||
|
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
||||||
|
# 注意:这里的Cookie需要根据实际情况更新
|
||||||
|
'Cookie': f'route=db9e9ef21068edc0ed70b7551d42bc4a; JSESSIONID={jsessionid}'
|
||||||
|
}
|
||||||
|
|
||||||
|
# 发起GET请求
|
||||||
|
url = 'https://jwpd.jsei.edu.cn/xsxk/zzxkyzb_cxZzxkYzbIndex.html?gnmkdm=N253512&layout=default'
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
|
||||||
|
session_user_key = None
|
||||||
|
first_xkkz_id = None
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
|
|
||||||
|
# 获取sessionUserKey
|
||||||
|
session_user_key_tag = soup.find('input', {'id': 'sessionUserKey'})
|
||||||
|
if session_user_key_tag and 'value' in session_user_key_tag.attrs:
|
||||||
|
session_user_key = session_user_key_tag['value']
|
||||||
|
|
||||||
|
# 获取firstXkkzId
|
||||||
|
first_xkkz_id_tag = soup.find('input', {'id': 'firstXkkzId'})
|
||||||
|
if first_xkkz_id_tag and 'value' in first_xkkz_id_tag.attrs:
|
||||||
|
first_xkkz_id = first_xkkz_id_tag['value']
|
||||||
|
return session_user_key, first_xkkz_id
|
||||||
|
def fetch_course_details(course_name,xkkz_id):
|
||||||
|
url = "https://jwpd.jsei.edu.cn/xsxk/zzxkyzb_cxZzxkYzbPartDisplay.html?gnmkdm=N253512"
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
'Host': 'jwpd.jsei.edu.cn',
|
||||||
|
'Connection': 'keep-alive',
|
||||||
|
'Content-Length': '543',
|
||||||
|
'sec-ch-ua-platform': '"Windows"',
|
||||||
|
'X-Requested-With': 'XMLHttpRequest',
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0',
|
||||||
|
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
||||||
|
'sec-ch-ua': '"Chromium";v="134", "Not:A-Brand";v="24", "Microsoft Edge";v="134"',
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
||||||
|
'sec-ch-ua-mobile': '?0',
|
||||||
|
'Origin': 'https://jwpd.jsei.edu.cn',
|
||||||
|
'Sec-Fetch-Site': 'same-origin',
|
||||||
|
'Sec-Fetch-Mode': 'cors',
|
||||||
|
'Sec-Fetch-Dest': 'empty',
|
||||||
|
'Referer': 'https://jwpd.jsei.edu.cn/xsxk/zzxkyzb_cxZzxkYzbIndex.html?gnmkdm=N253512&layout=default',
|
||||||
|
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
||||||
|
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
||||||
|
'Cookie': f'route=db9e9ef21068edc0ed70b7551d42bc4a; JSESSIONID={jsessionid}'
|
||||||
|
}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'filter_list[0]': course_name,
|
||||||
|
'rwlx': '2',
|
||||||
|
'xklc': '2',
|
||||||
|
'xkly': '0',
|
||||||
|
'bklx_id': '0',
|
||||||
|
'sfkkjyxdxnxq': '0',
|
||||||
|
'kzkcgs': '0',
|
||||||
|
'xqh_id': '1',
|
||||||
|
'jg_id': '02',
|
||||||
|
'njdm_id_1': '2024',
|
||||||
|
'zyh_id_1': '0230',
|
||||||
|
'gnjkxdnj': '0',
|
||||||
|
'zyh_id': '0230',
|
||||||
|
'zyfx_id': 'wfx',
|
||||||
|
'njdm_id': '2024',
|
||||||
|
'bh_id': '0230242',
|
||||||
|
'bjgkczxbbjwcx': '0',
|
||||||
|
'xbm': '1',
|
||||||
|
'xslbdm': '12',
|
||||||
|
'mzm': '01',
|
||||||
|
'xz': '3',
|
||||||
|
'ccdm': '4',
|
||||||
|
'xsbj': '0',
|
||||||
|
'sfkknj': '0',
|
||||||
|
'sfkkzy': '0',
|
||||||
|
'kzybkxy': '0',
|
||||||
|
'sfznkx': '0',
|
||||||
|
'zdkxms': '0',
|
||||||
|
'sfkxq': '0',
|
||||||
|
'sfkcfx': '0',
|
||||||
|
'kkbk': '0',
|
||||||
|
'kkbkdj': '0',
|
||||||
|
'sfkgbcx': '0',
|
||||||
|
'sfrxtgkcxd': '0',
|
||||||
|
'tykczgxdcs': '0',
|
||||||
|
'xkxnm': '2024',
|
||||||
|
'xkxqm': '12',
|
||||||
|
'kklxdm': '10',
|
||||||
|
'bbhzxjxb': '0',
|
||||||
|
'xkkz_id': xkkz_id,
|
||||||
|
'rlkz': '0',
|
||||||
|
'xkzgbj': '0',
|
||||||
|
'kspage': '1',
|
||||||
|
'jspage': '10',
|
||||||
|
'jxbzb': ''
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(url, headers=headers, data=data)
|
||||||
|
response_data = response.json()
|
||||||
|
|
||||||
|
kch_ids = []
|
||||||
|
if 'tmpList' in response_data and isinstance(response_data['tmpList'], list):
|
||||||
|
for course in response_data['tmpList']:
|
||||||
|
kcmc = course.get('kcmc', '未找到课程名称')
|
||||||
|
kch_id = course.get('kch_id', '未找到课程编号')
|
||||||
|
print(f"课程名称: {kcmc}")
|
||||||
|
kch_ids.append(kch_id)
|
||||||
|
else:
|
||||||
|
print("响应数据格式不正确或为空")
|
||||||
|
|
||||||
|
return kch_ids
|
||||||
|
def search_kc(kch_id,xkkz_id):
|
||||||
|
# 请求URL
|
||||||
|
url = "https://jwpd.jsei.edu.cn/xsxk/zzxkyzbjk_cxJxbWithKchZzxkYzb.html?gnmkdm=N253512"
|
||||||
|
|
||||||
|
# 请求头
|
||||||
|
headers = {
|
||||||
|
'Host': 'jwpd.jsei.edu.cn',
|
||||||
|
'Connection': 'keep-alive',
|
||||||
|
'Content-Length': '534',
|
||||||
|
'sec-ch-ua-platform': '"Windows"',
|
||||||
|
'X-Requested-With': 'XMLHttpRequest',
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0',
|
||||||
|
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
||||||
|
'sec-ch-ua': '"Chromium";v="134", "Not:A-Brand";v="24", "Microsoft Edge";v="134"',
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
||||||
|
'sec-ch-ua-mobile': '?0',
|
||||||
|
'Origin': 'https://jwpd.jsei.edu.cn',
|
||||||
|
'Sec-Fetch-Site': 'same-origin',
|
||||||
|
'Sec-Fetch-Mode': 'cors',
|
||||||
|
'Sec-Fetch-Dest': 'empty',
|
||||||
|
'Referer': 'https://jwpd.jsei.edu.cn/xsxk/zzxkyzb_cxZzxkYzbIndex.html?gnmkdm=N253512&layout=default',
|
||||||
|
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
||||||
|
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
||||||
|
'Cookie': f'route=db9e9ef21068edc0ed70b7551d42bc4a; JSESSIONID={jsessionid}'
|
||||||
|
}
|
||||||
|
# 请求体
|
||||||
|
data = {
|
||||||
|
'rwlx': '2',
|
||||||
|
'xkly': '0',
|
||||||
|
'bklx_id': '0',
|
||||||
|
'sfkkjyxdxnxq': '0',
|
||||||
|
'kzkcgs': '0',
|
||||||
|
'xqh_id': '1',
|
||||||
|
'jg_id': '02',
|
||||||
|
'zyh_id': '0230',
|
||||||
|
'zyfx_id': 'wfx',
|
||||||
|
'txbsfrl': '0',
|
||||||
|
'njdm_id': '2024',
|
||||||
|
'bh_id': '0230242',
|
||||||
|
'xbm': '1',
|
||||||
|
'xslbdm': '12',
|
||||||
|
'mzm': '01',
|
||||||
|
'xz': '3',
|
||||||
|
'ccdm': '4',
|
||||||
|
'xsbj': '0',
|
||||||
|
'sfkknj': '0',
|
||||||
|
'gnjkxdnj': '0',
|
||||||
|
'sfkkzy': '0',
|
||||||
|
'kzybkxy': '0',
|
||||||
|
'sfznkx': '0',
|
||||||
|
'zdkxms': '0',
|
||||||
|
'sfkxq': '0',
|
||||||
|
'sfkcfx': '0',
|
||||||
|
'bbhzxjxb': '0',
|
||||||
|
'kkbk': '0',
|
||||||
|
'kkbkdj': '0',
|
||||||
|
'xkxnm': '2024',
|
||||||
|
'xkxqm': '12',
|
||||||
|
'xkxskcgskg': '1',
|
||||||
|
'rlkz': '0',
|
||||||
|
'cdrlkz': '0',
|
||||||
|
'rlzlkz': '1',
|
||||||
|
'kklxdm': '10',
|
||||||
|
'kch_id': kch_id,
|
||||||
|
'jxbzcxskg': '0',
|
||||||
|
'xklc': '2',
|
||||||
|
'xkkz_id': xkkz_id,
|
||||||
|
'cxbj': '0',
|
||||||
|
'fxbj': '0'
|
||||||
|
}
|
||||||
|
response = requests.post(url, headers=headers, data=data)
|
||||||
|
response_data = response.json()
|
||||||
|
if response_data and isinstance(response_data, list):
|
||||||
|
do_jxb_id = response_data[0].get('do_jxb_id', '未找到do_jxb_id')
|
||||||
|
else:
|
||||||
|
do_jxb_id = '响应数据格式不正确或为空'
|
||||||
|
return do_jxb_id
|
||||||
|
def xuanke(do_jxb_id, kch_id,xkkz_id):
|
||||||
|
url = "https://jwpd.jsei.edu.cn/xsxk/zzxkyzbjk_xkBcZyZzxkYzb.html?gnmkdm=N253512"
|
||||||
|
# 请求头
|
||||||
|
headers = {
|
||||||
|
'Host': 'jwpd.jsei.edu.cn',
|
||||||
|
'Connection': 'keep-alive',
|
||||||
|
'Content-Length': '615',
|
||||||
|
'sec-ch-ua-platform': '"Windows"',
|
||||||
|
'X-Requested-With': 'XMLHttpRequest',
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0',
|
||||||
|
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
||||||
|
'sec-ch-ua': '"Chromium";v="134", "Not:A-Brand";v="24", "Microsoft Edge";v="134"',
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
||||||
|
'sec-ch-ua-mobile': '?0',
|
||||||
|
'Origin': 'https://jwpd.jsei.edu.cn',
|
||||||
|
'Sec-Fetch-Site': 'same-origin',
|
||||||
|
'Sec-Fetch-Mode': 'cors',
|
||||||
|
'Sec-Fetch-Dest': 'empty',
|
||||||
|
'Referer': 'https://jwpd.jsei.edu.cn/xsxk/zzxkyzb_cxZzxkYzbIndex.html?gnmkdm=N253512&layout=default',
|
||||||
|
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
||||||
|
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
||||||
|
'Cookie': f'route=db9e9ef21068edc0ed70b7551d42bc4a; JSESSIONID={jsessionid}'
|
||||||
|
}
|
||||||
|
# 请求体
|
||||||
|
data = {
|
||||||
|
'jxb_ids': f'{do_jxb_id}',
|
||||||
|
'kch_id': kch_id,
|
||||||
|
'qz': '0',
|
||||||
|
'xkkz_id': xkkz_id,
|
||||||
|
}
|
||||||
|
response = requests.post(url, headers=headers, data=data)
|
||||||
|
try:
|
||||||
|
response_data = response.json()
|
||||||
|
if 'flag' in response_data and response_data['flag'] == "1":
|
||||||
|
print("选课成功!")
|
||||||
|
else:
|
||||||
|
print(f"选课失败。服务器返回: {response_data}")
|
||||||
|
except ValueError:
|
||||||
|
print("无法解析服务器响应。请检查网络或请求数据。服务器返回:")
|
||||||
|
print(response.text)
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# 调用get_xkkz_id_and_sessionUserKey获取必要信息
|
||||||
|
session_user_key, xkkz_id = get_xkkz_id_and_sessionUserKey()
|
||||||
|
if not xkkz_id:
|
||||||
|
print("选课系统未开放!")
|
||||||
|
else:
|
||||||
|
course_name = input("请输入需要抢课的课程名称:")
|
||||||
|
kch_ids = fetch_course_details(course_name, xkkz_id)
|
||||||
|
for kch_id in kch_ids:
|
||||||
|
do_jxb_id = search_kc(kch_id, xkkz_id) # 注意添加了xkkz_id参数
|
||||||
|
if do_jxb_id != '未找到do_jxb_id' and do_jxb_id != '响应数据格式不正确或为空':
|
||||||
|
xuanke(do_jxb_id, kch_id, xkkz_id) # 注意添加了xkkz_id参数
|
Loading…
Reference in New Issue
Block a user