闯越自动签到demo版补充说明
demo代码:https://www.cnblogs.com/canmeng/p/11000548.html
定位出错是由于cookie 我重新登录账号过,cookies的值就变了
当时没注意cookie的值变化,然而定位参数回复仍然回复成功
{"state":1,"meg":"成功","result":{}}
至于获取cookie可以参考https://www.cnblogs.com/fengpingfan/p/4759671.html
保存文件名为cookie.txt
格式化为
key=value;key=value;key=value;
提交写入日志后,cookies添加了一个类似这样子的值
wLog_interContent=2019-06-25%0d%0a%e6%97%a0%e4%ba%ba%e5%80%bc%e5%ae%88%0d%0a%e6%af%8f%e6%97%a5%e6%97%a5%e5%bf%97;wLog_InternStateId=3;wLog_logImg=;wLog_newlogImg=;wLog_posAddress=;wLog_posLong=;wLog_posLati=;
根据上面的情况,改进代码如下
#! /usr/bin/python3
# -*- coding:UTF-8 -*-
# time : 2019/5/19 20:53
# file : requestforCH.py
# By 卤蛋
from urllib.parse import quote
import datetime
import requests
import calendar
import sys
import time
import random
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) request = requests.session() d = datetime.datetime.now() StateId = 3 index_html = __file__.replace("requestforCH.py", "") + "index.html" UserAgent_list = [r"Mozilla/5.0 (Linux; Android 8.1.0; Redmi 6 Build/O11019; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36",
r"Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19",
r"Mozilla/5.0 (Linux; U; Android 4.0.4; en-gb; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
r"Mozilla/5.0 (Linux; U; Android 6.2; en-gb; GT-P1000 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"] with open(__file__.replace("requestforCH.py", "") + r'cookie.txt', 'r') as file:
cookie = file.read()
cookies = {} # 初始化cookies字典变量
for line in cookie.split(';'): # 按照字符:进行划分读取
# 其设置为1就会把字符串拆分成2份
name, value = line.strip().split('=', 1)
cookies[name] = value # 为字典cookies添加内容 random_num = random.randint(0, len(UserAgent_list)-1) def UserAgent():
#return UserAgent_list[random_num]
return UserAgent_list[0] def locationStateAdd(userid):
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Host": "sqg.cydgsx.com",
"Connection": "Keep-Alive",
"Accept-Encoding": "gzip",
"User-Agent": "okhttp/3.10.0",
}
data = {"params": str({"state": StateId, "user_id": userid})}
response = request.get(
url="https://sqg.cydgsx.com/locationStateAdd",
headers=headers,
data=data,
timeout=60,
verify=False)
return response.json() def studentLocationAdd(userid):
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Host": "sqg.cydgsx.com",
"Connection": "Keep-Alive",
"Accept-Encoding": "gzip",
"User-Agent": r"okhttp/3.10.0",
}
data = {"params": '{"address":"中国广东省广州市海珠区","latitude":"23.09610289210092","longitude":"113.33666163412784","user_id":%s}' % userid}
response = request.post(
url="https://sqg.cydgsx.com/studentLocationAdd",
data=data,
headers=headers,
timeout=60,
verify=False)
print("定位:",response.text)
for key, value in response.json().items():
if value == "成功" and key == "meg":
return True
return False def Index(url="https://sqg.cydgsx.com/m/s/log/Index",cookie_dict={}):
headers = {
"Host": "sqg.cydgsx.com",
"Connection": "keep-alive",
"Upgrade-Insecure-Requests": "",
"User-Agent": UserAgent(),
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Referer": url,
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,en-US;q=0.9",
"X-Requested-With": "com.gcykj.boss",
}
temp_cookies = cookies.copy()
temp_cookies.update(cookie_dict)
response = request.get(
url=url,
headers=headers,
cookies=temp_cookies,
timeout=60,
verify=False)
html = response.text.replace('href="', 'href="https://sqg.cydgsx.com').replace("'get','", "'get','https://sqg.cydgsx.com").replace(r'src="', 'src="https://sqg.cydgsx.com')
with open(index_html, "w", encoding='utf-8') as file:
file.write(html)
print(locationStateAdd(cookies["LoginUser_Id"].split("&")[0])) # 等待服务器添加定位
return studentLocationAdd(cookies["LoginUser_Id"].split("&")[0]) # 添加定位 def day(string=d.strftime('%Y-%m-%d')): if d.day == getMonthFirstDayAndLastDay()[1].day:
month(d.strftime('%Y-%m-%d') + "\n无人值守\n" + "每月小结")
elif d.weekday() == 6:
week(d.strftime('%Y-%m-%d') + "\n无人值守\n" + "每周周报")
headers = {
"Host": "sqg.cydgsx.com",
"User-Agent": UserAgent(),
"Referer": "https://sqg.cydgsx.com/m/s/log/wLog",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,en-US;q=0.9",
"Accept": "application/json",
"Origin": "https://sqg.cydgsx.com",
"X-Requested-With": "XMLHttpRequest",
"Connection": "keep-alive",
"Content-Type": "application/x-www-form-urlencoded"
} data = {"InternStateId": StateId,
"interContent": quote(string, 'utf-8'),
"logImg": "",
"newlogImg": "",
"posAddress": "",
"posLong": "",
"posLati": ""}
response = request.post(
url="https://sqg.cydgsx.com/m/s/Log/SaveWriteLog",
data=data,
headers=headers,
cookies=cookies,
timeout=60,
verify=False)
print("cookies: ",response.cookies.items())
for key, value in response.json().items():
if value == "成功" and key == "meg":
print("每日小结: ",response.json())
return True
return False def week(string=d.strftime('%Y-%m-%d')):
if d.weekday() != 6:
return False
else:
headers = {
"Host": "sqg.cydgsx.com",
"Connection": "keep-alive",
"Accept": "application/json",
"Origin": "https://sqg.cydgsx.com",
"X-Requested-With": "XMLHttpRequest",
"User-Agent": UserAgent(),
"Content-Type": "application/x-www-form-urlencoded",
"Referer": "https://sqg.cydgsx.com/m/s/log/wWeekSmy?date={}".format(d.strftime('%Y-%m-%d')),
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,en-US;q=0.9",
}
data = {
"summaryInfo": string,
"logImg": "",
"newlogImg": "",
"smyDate": quote(d.strftime('%Y/%m/%d'),
'utf-8').replace("2F05%",
"2F5%") + "+" + quote("0:00:00", 'utf-8'),
"summaryType": "周小结",
}
response = request.post(
url="https://sqg.cydgsx.com/m/s/Log/SaveSmyJson",
data=data,
headers=headers,
cookies=cookies,
timeout=60,
verify=False) for key, value in response.json().items():
if value == "成功" and key == "meg":
print("每周小结: ",response.json())
return True
return False def month(string=d.strftime('%Y-%m-%d')):
if d.day != getMonthFirstDayAndLastDay()[1].day:
return False
else:
headers = {
"Host": "sqg.cydgsx.com",
"Connection": "keep-alive",
"Accept": "application/json",
"Origin": "https://sqg.cydgsx.com",
"X-Requested-With": "XMLHttpRequest",
"User-Agent": UserAgent(),
"Content-Type": "application/x-www-form-urlencoded",
"Referer": "https://sqg.cydgsx.com/m/s/log/wMonthSmy?date={}".format(d.strftime('%Y-%m-%d')),
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,en-US;q=0.9",
} data = {
"summaryInfo": string,
"logImg": "",
"newlogImg": "",
"smyDate": quote(d.strftime('%Y/%m/%d'),
'utf-8').replace("%2F0", "%2F") + "+" + quote("22:32:00", 'utf-8'),
"summaryType": "月小结",
}
response = request.post(
url="https://sqg.cydgsx.com/m/s/Log/SaveSmyJson",
data=data,
headers=headers,
cookies=cookies,
timeout=60,
verify=False) for key, value in response.json().items():
if value == "成功" and key == "meg":
print("每月小结: ",response.json())
return True
return False def getMonthFirstDayAndLastDay(year=None, month=None):
if year:
year = int(year)
else:
year = datetime.date.today().year if month:
month = int(month)
else:
month = datetime.date.today().month firstDayWeekDay, monthRange = calendar.monthrange(year, month) return [
datetime.date(
year=year,
month=month,
day=1),
datetime.date(
year=year,
month=month,
day=monthRange)] def main(data=""):
def setLog(data):
if sys.argv[1] == "day":
return day(data + "每日日志")
elif sys.argv[1] == "week":
return week(data + "每周周报")
elif sys.argv[1] == "month":
return month(data + "每月小结")
if len(sys.argv) > 2:
return setLog("".join(sys.argv[2:]))
elif len(sys.argv) > 1:
return setLog(data)
else:
return day(data + "每日日志") if __name__ == '__main__':
print("##"*20)
# Index("https://sqg.cydgsx.com/m/s/Home/Index")
if main(d.strftime('%Y-%m-%d') + "\n无人值守\n"):
print(d.strftime('%Y-%m-%d %H:%M:%S') + "\t成功写入日志")
temp_dict = {"wLog_interContent":quote(d.strftime('%Y-%m-%d') + "\n无人值守\n每日日志", 'utf-8')}
temp_dict["wLog_InternStateId"] = str(StateId)
temp_dict["wLog_logImg"] = ""
temp_dict["wLog_newlogImg"] = ""
temp_dict["wLog_posAddress"] = ""
temp_dict["wLog_posLong"] = ""
temp_dict["wLog_posLati"] = ""
print(Index("https://sqg.cydgsx.com/m/s/log/Index",temp_dict))
else:
print(d.strftime('%Y-%m-%d %H:%M:%S') + "\n写入日志失败")
print("==" * 20 + "\n闯越自动写日志系统(更新版)\tBy:卤蛋 \n2019.05.20·06.25\n" + "==" * 20)
print("##"*20)
闯越自动签到demo版补充说明的更多相关文章
- 基于python3.7的一个闯越自动签到脚本--demo版
望指正demo的定位,有时候会抽风无法接受我的定位信息 #! /usr/bin/python3 # -*- coding:UTF- -*- # time : // : # file : chuangy ...
- python3+任务计划实现的人人影视网站自动签到
python3+任务计划实现的人人影视网站自动签到 这是一个自动化程度较高的程序,运行本程序后会从chrome中读取cookies用于登录人人影视签到, 并且会自动添加一个windows 任务计划,这 ...
- Python 实现 T00ls 自动签到脚本(邮件+钉钉通知)
T00ls 每日签到是可以获取 TuBi 的,由于常常忘记签到,导致损失了很多 TuBi .于是在 T00ls 论坛搜索了一下,发现有不少大佬都写了自己的签到脚本,签到功能实现.定时任务执行以及签到提 ...
- 360每日自动签到,领取积分 (java httpclient4.x)
如何登陆360,并每日自动签到这次的难点主要集中在登陆这里了,开始抓包发现360登陆验证很麻烦,但是后来发现一个简单的方法.因为我安装了360安全卫士,发现点击那个金币的按钮能直接验证登陆,哈哈~所以 ...
- python写的自动签到脚本。
等以后有时间补上. 附上代码: #! /usr/bin/env python # coding:utf-8 #-----------------------------------------学号和密 ...
- 转:基于开源项目OpenCV的人脸识别Demo版整理(不仅可以识别人脸,还可以识别眼睛鼻子嘴等)【模式识别中的翘楚】
文章来自于:http://blog.renren.com/share/246648717/8171467499 基于开源项目OpenCV的人脸识别Demo版整理(不仅可以识别人脸,还可以识别眼睛鼻子嘴 ...
- 《JavaScript闯关记》视频版硬广
<JavaScript闯关记>视频版硬广 stone 在菜航工作时,兼任内部培训讲师,主要负责 JavaScript 基础培训,2016年整理的<JavaScript闯关记>课 ...
- 利用Python实现App自动签到领取积分
要自动签到,最简单的是打开页面分析请求,然后我们用脚本实现请求的自动化.但是发现食行没有页面,只有 APP,这不是一个好消息,这意味着需要抓包处理了. 有需要Python学习资料的小伙伴吗?小编整理[ ...
- selenium之数据驱动框架应用WPS个人中心自动签到
wps在注册后,有个每日签到的功能,签到后有几率送wps的专属金币[稻米],为了免费获得,又不想每天都是人工去执行签到动作,所以用selenium写了个小脚本,准备用数据驱动框架来完成这个事情,数据驱 ...
随机推荐
- linux之sed的用法
sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行替换.删除.新增.选取等特定工作,下面先了解一下sed的用法sed命令行格式为: sed ...
- Docker最全教程之使用PHP搭建个人博客站点(二十二)
目录 官方镜像 编写简单的Hello world! 1. 编写Hello world! 2. 编写Dockerfile 3. 构建并运行 4. 直接使用PHP Docker镜像运行PHP脚本 构建自 ...
- 解决ARCGIS10.2与VS2013不兼容
在注册表中HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0增加类型为REG_SZ的InstallDir节点.Ins ...
- 二、React中的更新
创建更新的方式:ReactDOM.render||hydrate 初次渲染,然后是setState.forceUpdate 一.React.render() 步骤:创建ReactRoot.创建Fibe ...
- Eucalyptus-利用镜像启动一个Windows Server 2008r2实例
1.前言 使用kvm制作Eucalyptus镜像(Windows Server 2008r2为例)——http://www.cnblogs.com/gis-luq/p/3990792.html 上一篇 ...
- nginx配置文件语法高亮
下载文件 nginx.vim https://vim.sourceforge.io/scripts/script.php?script_id=1886 安装 下载 nginx.vim 文件到 ~/.v ...
- LeetCode Single Number III (xor)
题意: 给一个数组,其中仅有两个元素是出现1次的,且其他元素均出现2次.求这两个特殊的元素? 思路: 跟查找单个特殊的那道题是差不多的,只是这次出现了两个特殊的.将数组扫一遍求全部元素的异或和 x,结 ...
- nvm安装nodejs(安装在非系统盘内)
在使用nodejs时有时需要不同的版本之间进行切换,所以就用到了版本管理工具nvm,在windows系统下用的是nvm-windows,这里选择的是nvm-noinstall.zip免安装版本(需要配 ...
- 慎用python的pop和remove方法
申明:转载请注明出处!!! Python关于删除list中的某个元素,一般有两种方法,pop()和remove(). 如果删除单个元素,使用基本没有什么问题,具体如下. 1.pop()方法,传递的是待 ...
- IOS 线程描述
●什么是线程 ● 1个进程要想执行任务,必须得有线程(每1个进程至少要有1条线程) ● 线程是进程的基本执行单元,一个进程(程序)的所有任务都在线程中执行 ● 比如使用酷狗播放音乐.使用迅雷下载电影, ...