欢迎使用WordPress。这是您的第一篇文章。编辑或删除它,然后开始写作吧!
新的PCQQ就是一坨屎,教你用回老QQ
用新QQ的同学,如果你也觉得新QQ就是一坨屎,你可以用下面的方法用回老QQ:
打开你的QQ bin文件夹,类似于:C:\Program Files (x86)\Tencent\QQ\Bin
新QQ的文件是QQ.exe,老QQ的文件是下面的QQScLauncher.exe
你知道该怎么做了吧。
USB大容量存储设备被禁用 代码32
记录一下python写爬虫必须要注意的几个点
因为好久没写过爬虫了,这次单位有需求要爬取几TB的资料,在测试过程中遇到一些问题,总结下来,未来写爬虫的时候可以避坑。
问题1:JSON Object Key不存在。规范的情况下,返回的JSON对象数组应该是统一的,即使数据不存在也应该是空字符串或者null或者别的什么,但是这个系统过于老旧,编码也乱七八糟不规范,导致个别数据不存在的时候,压根不返回这个Key。
解决方案:
if 'key' not in item: continue
只需要判断一下这个key在不在item里,不在直接跳出此循环。
问题2:保存的文件名/路径有非法字符。在Windows下,创建的文件夹/文件时,文件名不能包含以下字符:
\ / : * ? " < > |
因此,如果文件名/路径名中有此些字符,需要替换掉,这里提供一个替换方法:
def string_format(str: string, replacement: string=''): illegal_words = ['\\', '/', '*', '?' '"', '<', '>', '|'] for word in illegal_words: if word in str: str = str.replace(word, replacement) return str
参数说明:str 要格式化的字符串,replacement 将非法字符替换成指定内容,不填写则替换空字符串。
Vue3 导出word代码,可导出数据+图片
网上搜到的代码都没办法直接使用,需要修改后才能用,我在这里发一版修改后的完美可用的代码,可以直接拿去用,也给自己留个备份。
我在使用网上搜到的代码的时候遇到一些问题,如果你也遇到了这些问题,那么表示这篇文章可以帮助你。
问题:
1、JSZIP版本太高(V3.x),导致docxtemplater无法使用,以及一些函数大改动。
2、Vue3使用的Vite而不是Webpack,因此 require,Buffer等功能不能使用。
解决方法:
1、手动将JSZIP由3.x改为2.3.0版本,重新npm i,即可解决。
2、Buffer要安装buffer依赖,使用
npm i buffer --save
进行安装,然后直接按如下引用:
import {Buffer} from "buffer";
另外,网络上的代码在加载图片处理依赖时使用的是
var ImageModule = require('docxtemplater-image-module-free');
需要改为
import ImageModule from "docxtemplater-image-module-free";
以上就是主要的问题所在,下面贴上完整代码和一些需要注意的东西。
完整代码
1、开始之前,你需要先安装如下依赖
-- 安装 docxtemplater npm install docxtemplater pizzip --save -- 安装 jszip-utils npm install jszip-utils --save -- 安装 jszip npm install jszip --save -- 安装 FileSaver npm install file-saver --save -- 安装 buffer 用作b64转buffer npm install buffer --save -- 安装 docxtemplater-image-module-free 用作图片处理 npm install docxtemplater-image-module-free --save
2、新建一个js文件,我是在/src/utils/下新建的fileExport.js,并粘贴如下内容。
import PizZip from 'jszip'; import docxtemplater from 'docxtemplater'; import JSZipUtils from 'jszip-utils'; import {saveAs} from 'file-saver'; import {Buffer} from "buffer"; import ImageModule from "docxtemplater-image-module-free"; const base64DataURLToArrayBuffer = (dataURL) => { const base64Regex = /^data:image\/(png|jpg|svg|svg\+xml);base64,/; if (!base64Regex.test(dataURL)) { return false; } const stringBase64 = dataURL.replace(base64Regex, ""); let binaryString; if (typeof window !== "undefined") { binaryString = window.atob(stringBase64); } else { binaryString = new Buffer(stringBase64, "base64").toString("binary"); } const len = binaryString.length; const bytes = new Uint8Array(len); for (let i = 0; i < len; i++) { const ascii = binaryString.charCodeAt(i); bytes[i] = ascii; } return bytes.buffer; } /** * 导出word,支持图片 * @param {Object} tempDocxPath 模板文件路径 * @param {Object} wordData 导出数据 * @param {Object} fileName 导出文件名 */ export const exportWord = (tempDocxPath, wordData, fileName, imageSize = {}) => { // 读取并获得模板文件的二进制内容 JSZipUtils.getBinaryContent(tempDocxPath, function (error, content) { if (error) { throw error; } let opts = {}; opts.centered = true; // 图片居中,在word模板中定义方式为{%%image} opts.fileType = "docx"; opts.getImage = function (chartId) { return base64DataURLToArrayBuffer(chartId); }; opts.getSize = function (img, tagValue, tagName) { // console.log(img);//ArrayBuffer数据 // console.log(tagValue);//base64数据 // console.log(tagName);//wordData对象的图像属性名 // 自定义指定图像大小 // eslint-disable-next-line no-prototype-builtins if (imageSize.hasOwnProperty(tagName)) { return imageSize[tagName]; } else { return [660, 440]; } } let imageModule = new ImageModule(opts); // 创建一个PizZip实例,内容为模板的内容 const zip = new PizZip(content); // 创建并加载docxtemplater实例对象 const doc = new docxtemplater(); doc.attachModule(imageModule); doc.loadZip(zip); doc.setData(wordData); try { // 用模板变量的值替换所有模板变量 doc.render(); } catch (error) { // 抛出异常 const e = { message: error.message, name: error.name, stack: error.stack, properties: error.properties }; console.log( JSON.stringify({ error: e }) ); throw error; } console.log('11'); // 生成一个代表docxtemplater对象的zip文件(不是一个真实的文件,而是在内存中的表示) const out = doc.getZip().generate({ type: 'blob', mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' }); // 将目标文件对象保存为目标类型的文件,并命名 saveAs(out, fileName); } ); };
3、参数说明
- tempDocxPath 是模板文件绝对路径
- wordData 模板数据
- fileName 要保存的文件名
- imageSize 图片大小,接受一个int对象,格式是{ width, height },单位是px,例如{ 400, 300 }
如需导出图片,则需要将图片转为base64后写入wordData对象内。
echarts转base64的方法是
echarts.getInstanceByDom(document.getElementById('echarts')).getDataURL({ type: 'png', backgroundColor: '#fff', pixelRatio: 1, })
4、模板变量
模板内变量要和wordData里的变量名一致。普通字段:{字段名},图片字段:{%字段名}
以上
ThinkPHP6 多应用模式调用其他控制器时需要填写$app参数,报错Required parameter ‘$app’ missing
如图所示,在多应用情况下,我调用User() 控制器,提示需要填写$app参数,
因为我所有的控制器都是 extends BaseController 的,所以查看BaseController的源码,发现如下
/** * 构造方法 * @access public * @param App $app 应用对象 */ public function __construct(App $app) { $this->app = $app; $this->request = $this->app->request; // 控制器初始化 $this->initialize(); }
调用时需要传入一个App对象。
在网上和文档里查了半天都没结果,自己猜出解决方案。
传入参数如下:
(new App())->initialize()
完整的也就是
$user = new User((new App())->initialize());
你学废了吗?
By the way,TP6的文档写的乱七八糟,我真特么是服了,遇到问题看文档屁用没有。
Python读取项目目录和子目录下的文件
我在functions文件夹下有个py,用来读取config目录里的配置文件,发现 ../config/config.json 报错文件不存在。
咨询了copilot之后,学习了需要用如下写法:
self.config_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'config/config.json')
好麻烦。
Electron真的是我见过最令人头痛的软件
Electron
一步一个报错
垃圾软件。
我再用Electron我就是狗!
#怒 #怒 #怒 #怒 #怒 #怒
青骄第二课堂全国青少年禁毒知识一键满分脚本
[admonition]转载请保留出处,严禁倒卖,倒卖者亲🐴biss[/admonition]
前言
去年发过的禁毒知识竞赛的满分脚本,今年还能用。重新发布一下。
按照下面使用方法使用可一键满分,不用进去答题。
有问题请进QQ群交流:1153448795
效果图:
使用方法
1、登录https://www.2-class.com/competition
2、按F12打开开发者工具,选择应用(Application) -> 左侧Cookie加号点开 -> 选择https://www.2-class.com/
3、复制右侧的asw_tc和sid的值
4、切换回控制台(Console) -> 在下方输入框里输入命令:window.__DATA__.reqtoken 并回车
5、复制双引号内的内容
6、运行脚本,依次输入以上3个数据。
代码
# -*- coding: utf-8 -*- import requests import json import time import random # 获取reqtoken的命令: window.__DATA__.reqtoken # cookie = 'acw_tc=76b20f6616659797159527027e3350e04399c20a051cfaf70874ad516c6900; sid=e993abc8-00ee-4173-9c36-abd5d059babd;' # reqtoken = '9f83d24e-7e12-4c47-a45b-b677694fa7a3' def yi_jian_man_fen(cookie, reqtoken): url = 'https://www.2-class.com/api/quiz/commit' headers = { 'Cookie': cookie, 'Content-Type': 'application/json', 'User-Agent': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50' } time = random.randint(100, 350) data = { "list": [ { "questionId": 2986, "questionContent": "B" }, { "questionId": 2989, "questionContent": "C" }, { "questionId": 2990, "questionContent": "D" }, { "questionId": 2959, "questionContent": "C" }, { "questionId": 2928, "questionContent": "C" }, { "questionId": 2960, "questionContent": "A" }, { "questionId": 2961, "questionContent": "C" }, { "questionId": 2897, "questionContent": "B" }, { "questionId": 2930, "questionContent": "D" }, { "questionId": 2898, "questionContent": "B" }, { "questionId": 2963, "questionContent": "A" }, { "questionId": 2932, "questionContent": "D" }, { "questionId": 2901, "questionContent": "A" }, { "questionId": 2966, "questionContent": "D" }, { "questionId": 2934, "questionContent": "C" }, { "questionId": 2904, "questionContent": "D" }, { "questionId": 2907, "questionContent": "D" }, { "questionId": 2972, "questionContent": "C" }, { "questionId": 2973, "questionContent": "A" }, { "questionId": 2912, "questionContent": "B" } ], "time": time, "reqtoken": reqtoken } result = requests.post(url=url, data=json.dumps(data), headers=headers, verify=False) print(result.text) if __name__ == '__main__': acw_tc = input('请输入acw_tc:') sid = input('请输入sid:') reqtoken = input('请输入token:') cookie = f'acw_tc={acw_tc}; sid={sid};' yi_jian_man_fen(cookie, reqtoken)
其他
不欢迎任何商业行为。
司马52pojie,10年多了,封我账号,祝52pojie早日倒闭。
Vue3 错误处理机制onErrorCaptured使用方法
大家好,我在做JSON转XML时出现,如果字符串格式是XML,但是却强制进行JSON -> XML操作,控制台会报错Syntex Error,这个错误是人为导致的,并不是代码有问题,因此我需要捕获这个错误并处理。
尝试过使用try catch来捕获,发现根本没用。
经过查阅文档,发现可以使用生命周期钩子onErrorCaptured来处理
下面是我的代码,各位在使用时可以借鉴。
onErrorCaptured((err) => { // 判断是错误还是异常 if (err.toString().indexOf('SyntaxError') !== -1) { ElNotification({ title: '程序出错', message: err.message, type: 'error', }) return false } })
err是返回的错误对象,你要查找特定的错误就得把他转字符串,你可以在控制台看到完整的错误信息(红色的),err.message只包含内容,不包含开头的错误或警告类型。
祝各位程序永无BUG