欢迎访问 YinBuLiao 的博客,目前正在调整文章模式首图样式~

使用ddddocr实现验证码识别

前情提要

博主闲得无聊想着给哥特动漫做一个自动签到,由于哥特动漫使用的程序是discuz所以自带了登录验证码

观察网页

2023-07-12T17:25:22.png2023-07-12T17:25:22.png

我们可以清楚地看到网站是有验证码的

这时候我第一时间就想到了DDDDOCR

验证码识别

首先将验证码部分切割出来

2023-07-12T17:27:15.png2023-07-12T17:27:15.png

定位到验证码部分
发现没有ID不好定位
那这时候右键复制它的完整XPATH
再使用截图将验证码截下来
使用DDDDOCR识别验证码

import ddddocr

ocr = ddddocr.DdddOcr(beta=True)

with open("test.jpg", 'rb') as f:
    image = f.read()

res = ocr.classification(image)

将识别出来的验证码进行填充则登录完毕

Nginx反代哔哩轻小说

Nginx代码:

location  ~* \.(php|jsp|cgi|asp|aspx)$
    {
        proxy_pass https://w.linovelib.com;
        proxy_set_header Host w.linovelib.com;
        #向后端传递访客 ip
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header Accept-Encoding "";
          sub_filter "w.linovelib.com" "novel.yinbuliao.cn";
          sub_filter "img1.readpai.com" "img.yinbuliao.cn";
        sub_filter_once off;
        add_header Cache-Control no-cache;
        #向后端传递访客 ip
       
        proxy_ssl_name w.linovelib.com[;
        proxy_ssl_server_name on;
     
    }
location /
{
    proxy_pass https://w.linovelib.com;
    proxy_set_header Host w.linovelib.com;
    #向后端传递访客 ip
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    #向后端传递访客 ip
   
    proxy_ssl_name w.linovelib.com;
    proxy_ssl_server_name on;
 
 
    #缓存设置
    add_header X-Cache $upstream_cache_status;
        #Set Nginx Cache
      proxy_set_header Accept-Encoding "";
        sub_filter "w.linovelib.com" "novel.yinbuliao.cn";
        sub_filter "img1.readpai.com" "img.yinbuliao.cn";
      sub_filter_once off;
           add_header Cache-Control no-cache;
    proxy_ignore_headers Set-Cookie Cache-Control expires;
    proxy_cache cache_one;
    proxy_cache_key $host$uri$is_args$args;
    proxy_cache_valid 200 304 301 302 120m;
    expires 12h;
}

这时我们发现图片无法加载,因为图片有防盗链
我们再用python反代图片站改Referer绕开防盗链

from flask import Flask, request, send_file
import requests
import io

app = Flask(__name__)

@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def proxy(path):
    url = 'https://img1.readpai.com/' + path
    headers = {'Referer': 'https://w.linovelib.com/'}
    response = requests.get(url, headers=headers)
    return send_file(io.BytesIO(response.content), mimetype='image/jpeg')

if __name__ == '__main__':
    app.run(debug=True)

这时我们就可以看见所有内容都可以正常显示了

原神Akebi资源文件汉化思路

从以下三条API获取中文内容

map_undeground_mines https://sg-public-api-static.hoyolab.com/common/map_user/ys_obc/v1/map/point/list?map_id=9&app_sn=ys_obc&lang=zh-cn
map_enkanomiya https://sg-public-api-static.hoyolab.com/common/map_user/ys_obc/v1/map/point/list?map_id=7&app_sn=ys_obc&lang=zh-cn
map_teyvat https://sg-public-api-static.hoyolab.com/common/map_user/ys_obc/v1/map/point/list?map_id=2&app_sn=ys_obc&lang=zh-cn

替换对应的name 注意!不能修改labels里的clear_name修改后会无法启动游戏


我所使用的替换代码

import json
# 读取文件
en = 'map_enkanomiya.json'
zh = 'map_enkanomiya_zh-cn.json'
with open(zh, 'r', encoding='utf-8') as f:
    maps_zh_cn = json.load(f)

with open(en, 'r', encoding='utf-8') as f:
    maps = json.load(f)

for key in maps['categories']:
    for i in range(len(maps['categories'])):
        if maps['categories'][i]['id'] == key['id']:
            maps['categories'][i]['name'] = key['name']
for key in maps['labels']:
    maps['labels'][key]['name'] = maps_zh_cn['labels'][key]['name']
# 写入maps.json
with open(en, 'w', encoding='utf-8') as f:
    json.dump(maps, f, ensure_ascii=False, indent=4)
# 输出结果
print(en + '替换完成')

Butterfly主题美化

美化原因

因为本人模板使用到了Butterfly但是我又想手机和电脑端分开显示banner于是进行了二开


修改教程

  1. header.php
<?php  $this->need('header_com.php'); ?>
<body style="zoom: 1;">
    <div id="web_bg"></div>
<div class="page" id="body-wrap">
<?php if (is_array($this->options->beautifyBlock) && in_array('ShowTopimg',$this->options->beautifyBlock)): ?>
<style>#page-header:not(.not-top-img):before{background-color:rgba(0,0,0,0) !important;}@media screen and (max-width:2560px){#page-header{background-image:url(<?php $this->options->headerimgpc() ?>)}}@media screen and (max-width:768px){#page-header{background-image:url(<?php $this->options->headerimgpe() ?>)}}</style>    
<header class="full_page" id="page-header"  class="page-header">
        <div id="site-info">
            <h1 id="site-title"><?php $this->options->description() ?></h1>
            <div id="site-subtitle">
                <span id="subtitle"></span>
            </div>
        </div>
        <div id="scroll-down"><i class="fas fa-angle-down scroll-down-effects"></i></div>
<?php else: ?>        
<header class="not-top-img" id="page-header">        
<?php endif; ?>      
<?php  $this->need('public/nav.php'); ?>
</header>
  1. functions.php

将133行修改为:

    $headerimgpc = new Typecho_Widget_Helper_Form_Element_Text('headerimgpc', NULL,_t('https://images.weserv.nl/?url=https://article.biliimg.com/bfs/article/93059e139a964c976153ea40b79f3d5d19ebb90d.jpg'), _t('主页顶图(banner image)[电脑]'), _t('填入主页头图链接'));
    $form->addInput($headerimgpc);
    
    $headerimgpe = new Typecho_Widget_Helper_Form_Element_Text('headerimgpe', NULL,_t('https://images.weserv.nl/?url=https://article.biliimg.com/bfs/article/e1e77993b7d05fce014124d6c67addfe8e003a52.jpg'), _t('主页顶图(banner image)[手机]'), _t('填入主页头图链接'));
    $form->addInput($headerimgpe);