本人用的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) + '处外链问题')