记录一下平时遇到的问题和解决方案
谷歌浏览器修改请求头【安卓,苹果,mac, win】
def get_js_function(js_path, func_name, o_token, uid):
with open(js_path, encoding='utf-8') as fp:
js = fp.read()
ctx = execjs.compile(js)
return ctx.call(func_name, o_token, uid)
//js文件位置,默认在同一目录下, js中调用的函数, 两个参数
token = get_js_function('jike.js', 'genToken', o_token, uid)
1、先根据对应的加密位置找到 rsa整体加密位置
![RSA加密位置](https://img-blog.csdnimg.cn/20200826203400566.png#pic_center)
2、整体复制rsa加密代码,根据缺啥补啥原则添加window对象
3、console.log(window)
//打一下window全局对象,查找是否含有加密函数
↓结果↓
**[Function: JSEncrypt] { version: '3.0.0-rc.1' }**
4、new window.JSEncrypt();对象
function RsaFun() {
var publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxwFju5VsN5E61YPjL/qD04hvqulhOxIzxWH2ZvSXZz/XY1xmwzq3avl3sKE6/rYMvTXMwULtMUaFRhvpsFFlmXHK0dOZ1/q7ruH1/sBT0Kx8aQafa5v02V4ARlR3hs85eznVWUfAW3EyGva+2uCVn869PtQfsf5ihdRT+FYGUBwIDAQAB';
var encrypt = new window.JSEncrypt(); //重要!!!!
encrypt.setPublicKey( //KEY RSA公钥
publicKey);
var rsa = encrypt.encrypt(JSON.stringify({
uid: '123456',
timeStamp: Math.round(new Date().getTime() / 1000)
}));
return rsa
}
console.log(RsaFun())
判断文件是否存在
import os
os.path.exists(test_file.txt)
#True
os.path.exists(no_exist_file.txt)
#False
判断文件夹是否存在
import os
os.path.exists(test_dir)
#True
os.path.exists(no_exist_dir)
#False
from fastapi import FastAPI
import uvicorn
import execjs, datetime
app = FastAPI()
from pydantic import BaseModel
# 声明参数模型
class Item(BaseModel):
o_token: str
uid: str
# 获取js代码
def get_js_function(js_path, func_name, o_token, uid):
with open(js_path, encoding='utf-8') as fp:
js = fp.read()
ctx = execjs.compile(js)
return ctx.call(func_name, o_token, uid)
# 取当前时间
def Now_time():
now_time = datetime.datetime.now()
now_time = now_time.strftime("%Y-%m-%d %H:%M:%S")
now_time = datetime.datetime.strptime(now_time, '%Y-%m-%d %H:%M:%S')
return now_time
@app.post("/jike/token")
async def read_item(data: Item):
o_token = data.o_token
uid = data.uid
print(o_token, uid, Now_time())
token = get_js_function('jike.js', 'genToken', o_token, uid)
return token
if __name__ == '__main__':
uvicorn.run(app, host='127.0.0.1', port=8000)
...此处省略加载打码
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, host='0.0.0.0', port=8000)
#服务器启动flask项目
python -m flask run --host 0.0.0.0 --port 80
#服务器启动FastApi
uvicorn api:app --host 0.0.0.0 --port 8080 --reload
系统时间不正确的时候,需要得到时间戳api
淘宝
http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp
苏宁
http://quan.suning.com/getSysTime.do
pip 更新:
python -m pip install --upgrade pip -ihttp://pypi.douban.com/simple --trusted-host pypi.douban.com
pip下载1
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn requests
pip下载2
Pip3 install fastapi -i https://pypi.douban.com/simple/
import re
import base64
#将需要使用的ico的图片以base64格式读出
open_icon = open('E:/360MoveData/Users/SJC/Desktop/favicon.ico',"rb")
b64str = base64.b64encode(open_icon.read()) #以base64的格式读出
open_icon.close()
write_data = "img=%s" % b64str
print(write_data)
# 保存json文件
def Save():
dictObj = {
'jinpai': {
'min_price': 0,
'max_price': 500,
'min_yong': 3,
'max_yong': 500,
},
'zuozuo': {
'min_price': 0,
'max_price': 500,
'min_yong': 3,
'max_yong': 500,
},
}
jsObj = json.dumps(dictObj)
fileObject = open('C:/Xiaobai/jsonFile.txt', 'w')
fileObject.write(jsObj)
fileObject.close()
# 读取json 文件
def read_json(pt_name):
try:
with open('C:/Xiaobai/jsonFile.txt', 'r', encoding='utf8') as f:
json_data = json.load(f)
# print(json_data)
for item in json_data:
# print(item)
if item == pt_name:
# print(json_data[item]['min_price'], json_data[item]['max_price'], json_data[item]['min_yong'],
# json_data[item]['max_yong'])
return json_data[item]['min_price'], json_data[item]['max_price'], json_data[item]['min_yong'], \
json_data[item]['max_yong']
except Exception as e:
print(e)
# 改变json中的价格
def change_json(pt_name, min_price, max_price, min_yong, max_yong):
try:
with open("C:/Xiaobai/jsonFile.txt", "r", encoding='utf-8') as jsonFile:
data = json.load(jsonFile)
data[pt_name] = {
'min_price': min_price,
'max_price': max_price,
'min_yong': min_yong,
'max_yong': max_yong,
}
with open("C:/Xiaobai/jsonFile.txt", "w") as jsonFile:
json.dump(data, jsonFile, ensure_ascii=False)
except Exception as e:
print(e)
time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
'2020-09-26 22:37:09'
time.strftime('%H:%M:%S',time.localtime(time.time()))
'22:37:15'
1、安装
Pip3 install mkdocs -i https://pypi.douban.com/simple/
2、安装模板
Pip3 install mkdocs-material -i https://pypi.douban.com/simple/
3、启动mkdocs
mkdocs serve
4、终止mkdocs
ctrl+c
5、插入网址
[]('www.baidu.com')
6、插入图片
![]('图片地址在线,本地都可以')
m3u8下载器: https://www.52pojie.cn/forum.php?mod=viewthread&tid=1216473&highlight=m3u8
撤销:Ctrl/Command + Z
重做:Ctrl/Command + Y
加粗:Ctrl/Command + B
斜体:Ctrl/Command + I
标题:Ctrl/Command + Shift + H
无序列表:Ctrl/Command + Shift + U
有序列表:Ctrl/Command + Shift + O
检查列表:Ctrl/Command + Shift + C
插入代码:Ctrl/Command + Shift + K
插入链接:Ctrl/Command + Shift + L
插入图片:Ctrl/Command + Shift + G
查找:Ctrl/Command + F
替换:Ctrl/Command + G