soarli

Python中requests库POST应用总结
科技馆from requests import Request, Session import re import...
扫描右侧二维码阅读全文
09
2021/06

Python中requests库POST应用总结

科技馆

from requests import Request, Session
import re
import time
 
while 1:
    url = 'https://wx.zzkjg.com/kjg/appointment/savePersonalAppointment'
    data = '{"list":[{"createtype":2,"userid":"xxxxxxxx","cardtype":"1","type":1,"personnum":1,"isappointment":1,"planid":"xxxxxxxx","personname":"李x","cardnumber":"xxxxxxxx","telphone":"150xxxxxxxx"},{"createtype":2,"userid":"xxxxxxxx","cardtype":"1","type":1,"personnum":1,"isappointment":2,"planid":"xxxxxxxx","personname":"董xx","cardnumber":"xxxxxxxx","telphone":"186xxxxxxxx"},{"createtype":2,"userid":"xxxxxxxx","cardtype":"1","type":1,"personnum":1,"isappointment":2,"planid":"xxxxxxxx","personname":"卫xx","cardnumber":"xxxxxxxx","telphone":"132xxxxxxxx"}]}'
    headers = {
        ':authority': 'wx.zzkjg.com',
        ':method': 'POST',
        ':path': '/kjg/appointment/savePersonalAppointment',
        ':scheme': 'https',
        'accept': 'application/json, text/plain, */*',
        'accept-encoding': 'gzip, deflate, br',
        'accept-language': 'zh-CN,zh;q=0.9',
        'content-length': '742',
        'content-type': 'application/json',
        'cookie': 'xxxxxxxx',
        'origin': 'https://wx.zzkjg.com',
        'referer': 'https://wx.zzkjg.com/site/index.html',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'sign': 'xxxxxxxx',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
    }
    s = Session()
    req = Request('POST', url, data=data, headers=headers)
    prepped = s.prepare_request(req)
    r = s.send(prepped)
    print(r.text)
    time.sleep(0.5)

查电费

from requests import Request, Session
import re,time
 
url = 'http://yktwx.henau.edu.cn/wechat/basicQuery/queryElecRoomInfo.html'
data = 'aid=xxxxxxxx&area=xxxxxxxx&building=xxxxxxxx&floor=xxxxxxxx&room=xxxxxxxx'
headers = {
    'Host': 'yktwx.henau.edu.cn',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    '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',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': '607',
    'Origin': 'http://yktwx.henau.edu.cn',
    'Connection': 'keep-alive',
    'Referer': 'http://yktwx.henau.edu.cn/wechat/basicQuery/queryElecRoomInfo.html',
    'Upgrade-Insecure-Requests': '1',
    'Cookie': 'JSESSIONID=xxxxxxxx'
}
s = Session()
req = Request('POST', url, data=data, headers=headers)
prepped = s.prepare_request(req)
r = s.send(prepped)
#print(r.text)
zz = re.findall(r"房间当前剩余电量.....度", r.text)
print(zz[0])

效果:

参考资料:

zhuanlan.zhihu.com/p/71614475

www.jb51.net/article/199901.htm

blog.csdn.net/williamgavin/article/details/81390014

最后修改:2021 年 06 月 10 日 11 : 58 PM

发表评论