[Python] 纯文本查看 复制代码
import base64
import time
import requests
from bs4 import BeautifulSoup
import re
def now():
return int(time.time())
Cookie = '这里替换成你的cookie'
heard = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8application/signed-exchange;v=b3;q=0.9',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'cache-control': 'no-cache',
'content-length': '4',
'content-type': 'application/x-www-form-urlencoded',
'cookie': Cookie,
'origin': 'https://exam.hm86.cn',
'pragma': 'no-cache',
'referer': 'https://exam.hm86.cn/vip/exam.html',
'sec-ch-ua': '"Microsoft Edge";v="107", "Chromium";v="107", "Not=A?Brand";v="24"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'document',
'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'same-origin',
'sec-fetch-user': '?1',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.42'
}
url = 'https://exam.hm86.cn/vip/answer.html'
r = requests.post(url, data={"ssm": ""}, headers=heard)
# r = open("./cc.html", "r", encoding="utf-8").read()
stime = now()
soup = BeautifulSoup(r.text, "html.parser")
st = soup.find("input", id="st").get("value")
csmpagerid = soup.find("input", id="csmpagerid").get("value")
examenpm = soup.find("input", id="examenpm").get("value")
print(st)
# time.sleep(1000)
data = soup.find_all("tbody", class_="topic_con")
xua = [0, 1, 2, 3]
qval = ''
timunum = 0
for i in data:
jiexi = i.find("font", class_="answercon").text
# print(jiexi)
timu = i.find("font", class_="title").text
# print(timu)
xuanxiang = i.find_all("font", class_="f14")
xuanxiangvalue = i.find_all("input")
value = []
for j in xuanxiangvalue:
value.append(j.get("value"))
tival = []
xuanval = ''
xuanxiangneirong = []
for j in xuanxiang:
res = re.findall('[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b\u4e00-\u9fa5]',
j.text)
cc = ""
for k in res:
cc = cc + k
xuanxiangneirong.append(cc)
# print(j)
if cc in jiexi:
tival.append(xuanxiang.index(j))
if timunum < 20:
if len(tival) > 1:
if "错误" in timu or "不正确" in timu:
for k in tival:
tival.remove(k)
if len(tival) > 1:
tival = [tival[0]]
if len(tival) == 0:
if timunum < 20:
print("本题为单选题,但是没有找到正确答案")
else:
print("本题为多选题,但是没有找到正确答案")
print("题目:", timu)
print("*" * 50)
print("选项:", xuanxiangneirong)
print("*" * 50)
print("解析:", jiexi)
print("*" * 50)
a = input("请手动选择正确答案,输入选项序号,多选题请用空格隔开,输入完毕后按回车键")
a = a.split(" ")
for k in a:
tival.append(int(k) - 1)
for xuanindex in tival:
xuanval = xuanval + str(value[xuanindex]) + ","
timunum = timunum + 1
print(xuanval)
print("*" * 50)
qval = qval + xuanval + "$"
# break
qval = qval.replace(",$", "$")
qval = qval.replace("$$", "$")
qval = qval[:-1]
print(qval)
heard = {
'Host': 'exam.hm86.cn',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0',
'Accept': 'text/html, */*; q=0.01',
'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Accept-Encoding': 'gzip, deflate, br',
'X-Requested-With': 'XMLHttpRequest',
'Origin': 'https://exam.hm86.cn',
'Connection': 'keep-alive',
'Referer': 'https://exam.hm86.cn/vip/login.html',
'Cookie': Cookie,
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'Sec-GPC': '1',
'Content-Length': '0',
'TE': 'trailers'
}
while True:
print(f"已开始{now() - stime}秒")
if now() - stime > 300:
print("时间大于180秒,自动提交")
if (now() - stime) % 10 == 0:
ssm = requests.post("https://exam.hm86.cn/com/common/appAction.jsp?action=ssm", headers=heard).text
temp_b = ssm.encode("utf-8") # 将字符串转换为二进制
content_b = base64.b64encode(temp_b)
ssm = content_b.decode('utf-8')
print(ssm)
data = {'st': st,
'result_content': qval,
'csmpagerid': csmpagerid,
'examenpm': examenpm,
'ssm': ssm}
r = requests.post("https://exam.hm86.cn/vip/exam/submit", headers=heard, data=data)
print(r.status_code)
print(r.text)
if not "答题时间太短" in r.text:
break
time.sleep(1)