本文小編為大家詳細(xì)介紹“怎么使用Python實(shí)現(xiàn)查詢考研成績(jī)的功能”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“怎么使用Python實(shí)現(xiàn)查詢考研成績(jī)的功能”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學(xué)習(xí)新知識(shí)吧。
創(chuàng)新互聯(lián)建站是一家集網(wǎng)站建設(shè),鐵西企業(yè)網(wǎng)站建設(shè),鐵西品牌網(wǎng)站建設(shè),網(wǎng)站定制,鐵西網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,鐵西網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
使用時(shí)請(qǐng)先在代碼所在目錄新建 info.json,內(nèi)容如下
{ "xm": "上岸人", "zjhm": "xxx", "ksbh": "xxx", "bkdwdm": "xxx", "sendEmail":"xxx", "code":"xxx", "toAddr":"xxx", "key":"xxx", "time":"120" }
并且根據(jù)如下字段說明將 info.json中各個(gè)字段修改為需要查詢的考研人的信息(準(zhǔn)考證上都有)
xm:姓名
zjhm:身份證號(hào)
ksbh:考生編號(hào)
bkdwdm:報(bào)考單位編號(hào)
sendEmail:發(fā)件人Email(可以是自己的Email)
code:發(fā)件人Email授權(quán)碼
toAddr:收件人Email
key:最后一門考的專業(yè)課名稱或者所含字符,例如數(shù)據(jù)結(jié)構(gòu)可以填寫數(shù)據(jù)結(jié)構(gòu)或數(shù)據(jù)
time:每隔多少秒查詢一次
可以使用QQ郵箱
進(jìn)入Web端,點(diǎn)擊設(shè)置 > 賬戶 > POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服務(wù)
理論上只要開啟SMTP服務(wù),然而反正在郵件客戶端登錄都是需要授權(quán)碼的,不如把這些服務(wù)都開了
然后點(diǎn)擊生成授權(quán)碼
一旦有查詢結(jié)果會(huì)直接發(fā)送到郵箱
#我的Python交流群:748989764 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:郵件服務(wù)器地址 port:郵件服務(wù)器端口 user:郵箱賬戶名 password:郵箱賬戶的授權(quán)碼(注意是授權(quán)碼,不是郵箱的登錄密碼) """ self.user = user self.password = password self.smtp = smtplib.SMTP() # 創(chuàng)建SMTP對(duì)象 self.smtp.connect(host=host, port=port) # 連接到SMTP服務(wù)器 self.smtp.login(user=self.user, password=self.password) # 登錄郵箱 def send(self, From, To, Subject, Context, to_addrs): """ Context:郵件正文 From:發(fā)送者昵稱(隨便?。? 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 aarch74) 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": "" } try: res = requests.post(url=url, headers=head, data=data) if res.ok == True: if info["key"] in res.text: print("[LOG] ?。。∫巡樵兊匠煽?jī)") email_op = EmailOP(host="smtp.qq.com", port=25, user=info["sendEmail"], password=info["code"]) email_op.send(From="996考研成績(jī)查詢機(jī)器人", To=info["xm"], Subject=info["xm"] + "您好,已查到成績(jī)?。?!", Context=res.text, to_addrs=info["toAddr"]) sys.exit() else: print("[LOG] 未查詢到結(jié)果") res.close() else: res.close() print("[ERROR] 網(wǎng)絡(luò)錯(cuò)誤,HTTP響應(yīng)狀態(tài)碼:" + str(res.status_code)) email_op = EmailOP(host="smtp.qq.com", port=25, user=info["sendEmail"], password=info["code"]) email_op.send(From="996考研成績(jī)查詢機(jī)器人", To="程序猿", Subject="報(bào)錯(cuò)了!快去修BUG!", Context="網(wǎng)絡(luò)錯(cuò)誤,HTTP響應(yīng)狀態(tài)碼:" + str(res.status_code), to_addrs=info["toAddr"]) 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考研成績(jī)查詢機(jī)器人", To="程序猿", Subject="報(bào)錯(cuò)了!快去修BUG!", Context="捕捉到異常,請(qǐng)查看程序,若程序停止請(qǐng)重新打開", to_addrs=info["toAddr"]) if __name__ == '__main__': print("[LOG] 服務(wù)已開啟") print("[LOG] 每間隔" + info["time"] + "秒查詢1次") try: # 登錄郵箱 email_op = EmailOP(host="smtp.qq.com", port=25, user=info["sendEmail"], password=info["code"]) # 發(fā)送郵件 email_op.send(From="996考研成績(jī)查詢機(jī)器人", To=info["xm"], Subject="服務(wù)已開啟", Context=info["xm"] + "您好,已經(jīng)開始為您查詢成績(jī)", to_addrs=info["toAddr"]) except smtplib.SMTPAuthenticationError as e: print("[ERROR] 登錄郵箱出現(xiàn)問題,請(qǐng)檢查info.json中sendEmail與code字段是否填寫正確") print("[ERROR] sendEmail填寫發(fā)件人郵箱,code填寫授權(quán)碼") print("[ERROR] ?。?!注意是授權(quán)碼,不是郵箱的登錄密碼") sys.exit() 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考研成績(jī)查詢機(jī)器人", To="程序猿", Subject="報(bào)錯(cuò)了!快去修BUG!", Context="捕捉到異常,請(qǐng)查看程序,若程序停止請(qǐng)重新打開", to_addrs=info["toAddr"]) main() time.sleep(int(info["time"]))
一旦有查詢結(jié)果會(huì)保存當(dāng)前目錄的res.html
#我的Python交流群:748989764 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" 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 aarch74) 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": "" } try: res = requests.post(url=url, headers=head, data=data) if res.ok == True: if info["key"] in res.text: print("[LOG] ?。?!已查詢到成績(jī)") with open("res.html", "w+", encoding='utf8') as f: f.write(res.text) sys.exit() else: print("[LOG] 未查詢到結(jié)果") res.close() else: res.close() print("[ERROR] 網(wǎng)絡(luò)錯(cuò)誤,HTTP響應(yīng)狀態(tài)碼:" + str(res.status_code)) except requests.exceptions.RequestException as e: print("[ERROR] 捕捉到異常,請(qǐng)查看程序,若程序停止請(qǐng)重新打開") 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: print("[ERROR] 捕捉到異常,請(qǐng)查看程序,若程序停止請(qǐng)重新打開") main() time.sleep(int(info["time"]))
讀到這里,這篇“怎么使用Python實(shí)現(xiàn)查詢考研成績(jī)的功能”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識(shí)點(diǎn)還需要大家自己動(dòng)手實(shí)踐使用過才能領(lǐng)會(huì),如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。