吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3083|回复: 8
收起左侧

[Python 原创] 河南zj知识竞赛自动答题

[复制链接]
dou520dou 发表于 2022-11-14 22:55
本帖最后由 dou520dou 于 2022-11-14 23:04 编辑

利用python进行自动答题,由于我没有题库就把选项和解析里面的内容做对比进行选择。
首先我们打开网站登录页面然后F12登录,抓取登录后的cookie放到代码的最上面的cookie变量
屏幕截图 2022-11-14 225518.png
。然后开始运行即可开始答题,当选项匹配不到解析里面的内容时将会提示在控制台自行选择答案输入1-4
[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)

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

rjybt 发表于 2022-11-17 17:48
感谢楼主分享
Stoic 发表于 2022-11-18 10:10
墨浔丈节 发表于 2022-11-18 17:06
娃娃菜啊 发表于 2023-3-30 15:08
你好,豫台大赛参加了嘛,能出个教程吗,网上已经有题库了
userfhy 发表于 2023-4-1 09:13
娃娃菜啊 发表于 2023-3-30 15:08
你好,豫台大赛参加了嘛,能出个教程吗,网上已经有题库了

现在天天让答题
娃娃菜啊 发表于 2023-4-2 20:24
userfhy 发表于 2023-4-1 09:13
现在天天让答题

看来兄台和我一样
fangjie88 发表于 2023-4-2 23:05
好思路。
liu82635 发表于 2023-7-4 11:49
楼主,能不能出个河南科协的答题脚本教程
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 21:58

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表