代码拉取完成,页面将自动刷新
import requests
from bs4 import BeautifulSoup
import os
# ****************登录*******************
# 自己的账号密码
# key为推送消息的
users = eval(os.environ['users'])
logUrl = "http://yiqing.ctgu.edu.cn/wx/index/loginSubmit.do"
def sentMsg(msg, key):
headers = {'Content-Type': 'application/json;charset=utf-8'}
api_url = "https://qmsg.zendee.cn/send/"+key+"?msg=" + msg
return requests.post(api_url, headers=headers, timeout=None).content
def sentOne(username, password, key):
header = {
# origin:http://yiqing.ctgu.edu.cn
# "Content-Type": "application/json;charset=UTF-8",
'Referer': "http://yiqing.ctgu.edu.cn/wx/index/login.do?currSchool=ctgu&CURRENT_YEAR=2019&showWjdc=false&studentShowWjdc=false",
# 模仿谷歌浏览器的登录
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36"
}
yiqingSession = requests.session()
yiqingSession.keep_alive = False
postData = {
"username": username,
"password": password
}
sentMsg(username, key)
try:
responseRes = yiqingSession.post(
logUrl, data=postData,headers =header,timeout=None)
sentMsg('登陆成功', key)
except:
try:
responseRes = yiqingSession.post(
logUrl, data=postData,headers =header,timeout=None)
sentMsg('登陆成功', key)
except:
try:
responseRes = yiqingSession.post(
logUrl, data=postData,headers =header,timeout=None)
sentMsg('登陆成功', key)
except:
sentMsg('网页无响应', key)
responseRes = yiqingSession.post(
logUrl, data=postData,headers =header,timeout=None)
# *******从提交页面获取 表单信息**********
# 构建表单(默认身体健康)
postData = {
"ttoken": '',
"province": "",
"city": "",
"district": "",
"adcode": "",
"longitude": "0",
"latitude": "0",
"sfqz": "否",
"sfys": "否",
"sfzy": "否",
"sfgl": "否",
"status": "1",
"sfgr": "否",
"szdz": "",
"sjh": "",
"lxrxm": '',
"lxrsjh": '',
"sffr": "否",
"sffy": "否",
"sfgr": "否",
"qzglsj": '',
"qzgldd": '',
"glyy": '',
"mqzz": '',
"sffx": "否",
"qt": "",
}
getFormurl = "http://yiqing.ctgu.edu.cn/wx/health/toApply.do"
responseRes = yiqingSession.get(getFormurl, timeout=5,headers =header, verify=False)
sentMsg('请求2', key)
# 获取必要信息填入表单
soup = BeautifulSoup(responseRes.text, "html.parser")
getFormlist = soup.find_all('input')[0:15]
for Formdata in getFormlist:
try:
postData[Formdata.attrs['name']] = Formdata.attrs['value']
except:
print("没name")
# *************提交最终表单***********
postFormurl = "http://yiqing.ctgu.edu.cn/wx/health/saveApply.do"
header['Referer'] = "http://yiqing.ctgu.edu.cn/wx/health/toApply.do"
responseRes = yiqingSession.post(
postFormurl, data=postData,headers =header, verify=False, timeout=None)
sentMsg('成功发送', key)
print(responseRes.text)
sentMsg(responseRes.text, key)
for username, password, key in users:
# start_new_thread(report,(usr,pas,))
sentOne(username, password, key)
# print(log[-1][-1])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。