CSDN 转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

本人用的github图床,转到csdn图片有时候会变成CSDN 转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传,脚本处理一下即可(脚本蹩脚,抛砖引玉)

直接改

# -*- coding: utf-8 -*-
# @Author: yq1ng
# @Date:   2021-05-20 17:22:08
# @Last Modified by:   yq1ng
# @Last Modified time: 2021-05-20 18:19:47

import re

old_path = "d:/code/python/md/old_file.md"
new_path = "d:/code/python/md/new_file.md"
old_file = open(old_path, 'r', encoding='utf-8')
new_file = open(new_path, 'w', encoding='utf-8')

old_line = old_file.readline()
count = 0

while old_line:
    if "![" in old_line:
        url = re.findall('https://.*png|https://.*jpeg|https://.*jpg', old_line)
        img = '<img src="' + url[0] + '"/>'
        new_line = re.sub('!\[.*\)', img, old_line)
        new_file.write(new_line)
        print(old_line + '   ===>   ' + new_line)
        count += 1
    else:
        new_file.write(old_line)
    old_line = old_file.readline()

old_file.close()
new_file.close()

print('\n已成功替换' + str(count) + '处外链问题')

先拷贝到csdn写文章区域,再拷贝到本地文件

# -*- coding: utf-8 -*-
# @Author: yq1ng
# @Date:   2021-05-20 17:22:08
# @Last Modified by:   yq1ng
# @Last Modified time: 2021-05-20 18:04:58

import re

old_path = "old_file"
new_path = "new_file"
old_file = open(old_path, 'r', encoding='utf-8')
new_file = open(new_path, 'w', encoding='utf-8')

old_line = old_file.readline()
count = 0

while old_line:
    if "外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传" in old_line:
        url = re.findall('https://.*png', old_line)
        img = '<img src="' + url[0] + '"/>'
        new_line = re.sub('\[外.*\]', img, old_line)
        new_file.write(new_line)
        print(old_line + '   ===>   ' + new_line)
        count += 1
    else:
        new_file.write(old_line)
    old_line = old_file.readline()

old_file.close()
new_file.close()

print('\n已成功替换' + str(count) + '处外链问题')
  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值