首页 > 编程语言 >【Python】Python实现提前查询考研成绩

【Python】Python实现提前查询考研成绩

时间:2023-02-19 17:57:23浏览次数:58  
标签:5.0 like Python Mozilla agent 查询 537.36 user 考研

✨Python实现提前查询考研成绩

自命题院校可能会在考研成绩正式发布之前将成绩上传到研招网,并进行测试

此时就可以提前查询到专业课成绩


✨使用说明

填写相关信息

使用时请先在代码所在目录新建info.json,内容如下

{
    "xm": "上岸人",
    "zjhm": "xxx",
    "ksbh": "xxx",
    "bkdwdm": "xxx",
    "sendEmail":"xxx",
    "code":"xxx",
    "toAddr":"xxx",
    "key":"xxx",
    "time":"120"
}

并且根据如下字段说明将info.json中各个字段修改为需要查询的考研人的信息(准考证上都有)

xm:姓名

zjhm:身份证号

ksbh:考生编号

bkdwdm:报考单位编号

sendEmail:发件人Email(可以是自己Email)

code:发件人Email授权码

toAddr:收件人Email

key:最后一门考的专业课名称或者所含字符,例如数据结构可以填写数据结构或数据

time:每个多少秒查询一次


发件人Email说明

可以使用QQ邮箱

进入Web端,点击设置 > 账户 > POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务

理论上只要开启SMTP服务,然而反正在邮件客户端登录都是需要授权码的,不如把这些服务都开了

然后点击生成授权码

image-20230219170355058


✨代码实现

查询成绩并且发送到邮箱版本(刺激

一旦有查询结果会直接发送到邮箱

import json
import random
import sys
import time
import requests
import smtplib
from email.mime.text import MIMEText
from email.header import Header

# import urllib3
# urllib3.disable_warnings()

url = "https://yz.chsi.com.cn/apply/cjcx/cjcx.do"
with open('info.json', 'r', encoding='UTF-8') as f:
    info = json.load(f)
# temp = "https://yz.chsi.com.cn/apply/cjcx/t/" + info["bkdwdm"] + ".dhtml"


class EmailOP:
    def __init__(self, host, port, user, password):
        """
        host:邮件服务器地址
        port:邮件服务器端口
        user:邮箱账户名
        password:邮箱账户的授权码(注意是授权码,不是邮箱的登录密码)
        """
        self.user = user
        self.password = password
        self.smtp = smtplib.SMTP()  # 创建SMTP对象
        self.smtp.connect(host=host, port=port)  # 连接到SMTP服务器
        self.smtp.login(user=self.user, password=self.password)  # 登录邮箱

    def send(self, From, To, Subject, Context, to_addrs):
        """
        Context:邮件正文
        From:发送者昵称(随便取)
        To:接收者昵称(随便取)
        Subject:邮件主题
        to_addrs: 收件人邮箱地址
        """
        message = MIMEText(Context, 'plain', 'utf-8')
        message['From'] = Header(From)
        message['To'] = Header(To)
        message['Subject'] = Header(Subject)
        self.smtp.sendmail(from_addr=self.user, to_addrs=to_addrs, msg=message.as_string())


def main():
    headers_list = [
        {
            'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.0.0; SM-G955U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 10; SM-G981B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (iPad; CPU OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.109 Safari/537.36 CrKey/1.54.248666'
        }, {
            'user-agent': 'Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.188 Safari/537.36 CrKey/1.54.250320'
        }, {
            'user-agent': 'Mozilla/5.0 (BB10; Touch) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.0.9.2372 Mobile Safari/537.10+'
        }, {
            'user-agent': 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML like Gecko) Version/7.2.1.0 Safari/536.2+'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; U; Android 4.3; en-us; SM-N900T Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; U; Android 4.1; en-us; GT-N7100 Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 7.0; SM-G950U Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.0.0; SM-G965U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.111 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.1.0; SM-T837A) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.80 Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; U; en-us; KFAPWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13 Safari/535.19 Silk-Accelerated=true'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; U; Android 4.4.2; en-us; LGMS323 Build/KOT49I.MS32310c) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 550) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 6.0.1; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 10 Build/MOB31T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.0.0; Nexus 5X Build/OPR4.170623.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 7.1.1; Nexus 6 Build/N6F26U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.0.0; Nexus 6P Build/OPP3.170518.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 7 Build/MOB30X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 520)'
        }, {
            'user-agent': 'Mozilla/5.0 (MeeGo; NokiaN9) AppleWebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 9; Pixel 3 Build/PQ1A.181105.017.A1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.158 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 10; Pixel 4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 11; Pixel 3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.181 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1'
        }, {
            'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
        }, {
            'user-agent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1'
        }, {
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.78"
        }
    ]

    head = {
        "User-Agent": str(random.choice(headers_list)["user-agent"]),
        "Referer": "https://yz.chsi.com.cn/apply/cjcx/t/" + info["bkdwdm"] + ".dhtml"
    }
    data = {
        "xm": info["xm"],
        "zjhm": info["zjhm"],
        "ksbh": info["ksbh"],
        "bkdwdm": info["bkdwdm"],
        "checkcode": ""
    }

    res = requests.post(url=url, headers=head, data=data)
    if res.ok == True:
        if info["key"] in res.text:
            print("[LOG] !!!已查询到成绩")
            email_op = EmailOP(host="smtp.qq.com", port=25, user=info["sendEmail"], password=info["code"])
            # 发送一封邮件
            email_op.send(From="996考研成绩查询机器人", To=info["xm"], Subject=info["xm"] + "您好,已查到成绩!!!", Context=res.text,
                         to_addrs=info["toAddr"])
            sys.exit()
        else:
            print("[LOG] 未查询到结果")
            res.close()
    else:
        res.close()
        email_op = EmailOP(host="smtp.qq.com", port=25, user=info["sendEmail"], password=info["code"])
        # 发送一封邮件
        email_op.send(From="996考研成绩查询机器人", To="程序猿", Subject="报错了!快去修BUG!", Context="网络错误" + str(res.status_code),
                     to_addrs=info["toAddr"])


if __name__ == '__main__':
    print("[LOG] 每间隔" + info["time"] + "秒查询1次")
    email_op = EmailOP(host="smtp.qq.com", port=25, user=info["sendEmail"], password=info["code"])
    # 发送邮件
    email_op.send(From="996考研成绩查询机器人", To=info["xm"], Subject="服务已开启", Context=info["xm"] + "您好,已经开始为您查询成绩", to_addrs=info["toAddr"])
    count = 0
    while True:
        try:
            count += 1
            print(f"[LOG] 第{count}次查询")
            main()
            time.sleep(int(info["time"]))
        except requests.exceptions.RequestException as e:
            email_op = EmailOP(host="smtp.qq.com", port=25, user=info["sendEmail"], password=info["code"])
            # 发送一封邮件
            email_op.send(From="996考研成绩查询机器人", To="程序猿", Subject="报错了!快去修BUG!", Context="捕捉到异常,请查看程序,若程序停止请重新打开",
                         to_addrs=info["toAddr"])
            main()
            time.sleep(int(info["time"]))

查询成绩并且注释掉了发送邮件版本

一旦有查询结果会保存当前目录的res.html

import json
import random
import sys
import time
import requests
import smtplib
from email.mime.text import MIMEText
from email.header import Header

# import urllib3
# urllib3.disable_warnings()

url = "https://yz.chsi.com.cn/apply/cjcx/cjcx.do"
with open('info.json', 'r', encoding='UTF-8') as f:
    info = json.load(f)
# temp = "https://yz.chsi.com.cn/apply/cjcx/t/" + info["bkdwdm"] + ".dhtml"


class EmailOP:
    def __init__(self, host, port, user, password):
        """
        host:邮件服务器地址
        port:邮件服务器端口
        user:邮箱账户名
        password:邮箱账户的授权码(注意是授权码,不是邮箱的登录密码)
        """
        # self.user = user
        # self.password = password
        # self.smtp = smtplib.SMTP()  # 创建SMTP对象
        # self.smtp.connect(host=host, port=port)  # 连接到SMTP服务器
        # self.smtp.login(user=self.user, password=self.password)  # 登录邮箱

    # def send(self, From, To, Subject, Context, to_addrs):
    #     """
    #     Context:邮件正文
    #     From:发送者昵称(随便取)
    #     To:接收者昵称(随便取)
    #     Subject:邮件主题
    #     to_addrs: 收件人邮箱地址
    #     """
    #     message = MIMEText(Context, 'plain', 'utf-8')
    #     message['From'] = Header(From)
    #     message['To'] = Header(To)
    #     message['Subject'] = Header(Subject)
    #     self.smtp.sendmail(from_addr=self.user, to_addrs=to_addrs, msg=message.as_string())


def main():
    headers_list = [
        {
            'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.0.0; SM-G955U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 10; SM-G981B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (iPad; CPU OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/87.0.4280.77 Mobile/15E148 Safari/604.1'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.109 Safari/537.36 CrKey/1.54.248666'
        }, {
            'user-agent': 'Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.188 Safari/537.36 CrKey/1.54.250320'
        }, {
            'user-agent': 'Mozilla/5.0 (BB10; Touch) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.0.9.2372 Mobile Safari/537.10+'
        }, {
            'user-agent': 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML like Gecko) Version/7.2.1.0 Safari/536.2+'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; U; Android 4.3; en-us; SM-N900T Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; U; Android 4.1; en-us; GT-N7100 Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 7.0; SM-G950U Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.0.0; SM-G965U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.111 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.1.0; SM-T837A) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.80 Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; U; en-us; KFAPWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13 Safari/535.19 Silk-Accelerated=true'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; U; Android 4.4.2; en-us; LGMS323 Build/KOT49I.MS32310c) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 550) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 6.0.1; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 10 Build/MOB31T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.0.0; Nexus 5X Build/OPR4.170623.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 7.1.1; Nexus 6 Build/N6F26U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.0.0; Nexus 6P Build/OPP3.170518.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 7 Build/MOB30X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 520)'
        }, {
            'user-agent': 'Mozilla/5.0 (MeeGo; NokiaN9) AppleWebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 9; Pixel 3 Build/PQ1A.181105.017.A1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.158 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 10; Pixel 4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 11; Pixel 3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.181 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36'
        }, {
            'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1'
        }, {
            'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
        }, {
            'user-agent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1'
        }, {
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.78"
        }
    ]

    head = {
        "User-Agent": str(random.choice(headers_list)["user-agent"]),
        "Referer": "https://yz.chsi.com.cn/apply/cjcx/t/" + info["bkdwdm"] + ".dhtml"
    }
    data = {
        "xm": info["xm"],
        "zjhm": info["zjhm"],
        "ksbh": info["ksbh"],
        "bkdwdm": info["bkdwdm"],
        "checkcode": ""
    }

    res = requests.post(url=url, headers=head, data=data)
    # print(res.text)
    # with open("res.html", "w+", encoding='utf8') as f:
    #     f.write(res.text)

    if res.ok == True:
        if info["key"] in res.text:
            print("[LOG]  !!!已查询到成绩")
            with open("res.html", "w+", encoding='utf8') as f:
                f.write(res.text)
        else:
            print("[LOG] 未查询到结果")
            res.close()


if __name__ == '__main__':
    print("[LOG] 每间隔" + info["time"] + "秒查询1次")
    count = 0
    while True:
        try:
            count += 1
            print(f"[LOG] 第{count}次查询")
            main()
            time.sleep(int(info["time"]))
        except requests.exceptions.RequestException as e:
            main()
            time.sleep(int(info["time"]))

✨使用效果

image-20230219172433036

image-20230219172615513


⭐转载请注明出处

本文作者:双份浓缩馥芮白

原文链接:https://www.cnblogs.com/Flat-White/p/17135166.html

版权所有,如需转载请注明出处。

标签:5.0,like,Python,Mozilla,agent,查询,537.36,user,考研
From: https://www.cnblogs.com/Flat-White/p/17135166.html

相关文章

  • 16.子查询
    1.定义子查询--子查询语法----在主查询之前,子查询会执行一次----子查询结果被用于主查询hr@ORCLPDB012023-02-1917:21:42>selectlast_name,salary2fromemplo......
  • python requests 最牛攻略
    目录安装ReuqestsHTTP简介什么是HTTPHTTP工作原理HTTP的9种请求方法HTTP状态码requests快速上手requests发起请求的步骤requests发起请求的两种方式请求参数发起GET......
  • 15.多表查询语句
    1.等值与不等值连接--限定模糊名:----1.使用前缀可提高性能----2.表别名可替代完整的表前缀----3.表别名给表一个简短的名字----4.使代码更短,使用更少内存----5.列别......
  • Python报错TypeError: 'NoneType' object is not callable
    Python报错TypeError:'NoneType'objectisnotcallable 保存内容如下  检查src文件后没有发现问题,最终在公共方法找到原因注释掉return了,取消后问题解决 ......
  • 简单的python格网算法算数据密集度demo
    #格网算法计算数据集区域数据密集度importtimeimportrandomimportnumpyasnpimportpandasaspd#模拟数据集defcreate_data():data_x=[]data_y......
  • python代码规范PEP8
    1、引言本文档给出了Python编码规约,主要Python发行版中的标准库即遵守该规约。对于C代码风格的Python程序,请参阅配套的C代码风格指南。本文档和PEP257(文档字......
  • 跟着廖雪峰学python 005
    ​ 函数的调用、定义、参数 ​编辑 #######命名关键字参数没完abs()函数:绝对值>>>abs(100)100>>>abs(-20)20max()函数:接收任意多个参数,并返回最大的那个......
  • 使用python批量转换.jfif文件为.jpg
    python代码如下,有需要的自行取用:需要引入Image库,方法是:pipinstallImage importosfromPILimportImageroot_dir=r'C:\temp'deflist_files(root_dir):......
  • python--matplotlib(1)
    前言 Matplotlib画图工具的官网地址是http://matplotlib.org/Python环境下实现Matlab制图功能的第三方库,需要numpy库的支持,支持用户方便设计出二维、三维数据的图形显示。......
  • 运行python程序时显示killed
    这是由于内存不足导致,以下命令可以拓展内存:sudoswapoff/swapfilesudoddif=/dev/zeroof=/swapfilebs=1Mcount=30720oflag=appendconv=notruncsudomkswap/sw......