首页 > Web开发 > 详细

html使用网络图片防盗问题解决

时间:2019-08-19 12:17:15      阅读:109      评论:0      收藏:0      [点我收藏+]

解决mkdocs图片防盗问题

前言

我在mkdocs上的图片是使用博客园上的,部署后无法正常显示。度娘了一下,只用在<head>后插入<meta name="referrer" content="no-referrer" />

写脚本

  • @遍历所在目录及其目录下所有的html文件,在第8行追加代码
# coding:utf-8
import os

def get_files(path='D:\zyt\\azyt\sfx', rule=".sfx"):
    all = []
    for fpathe,dirs,fs in os.walk(path):   # os.walk获取所有的目录
        for f in fs:
            filename = os.path.join(fpathe,f)
            if filename.endswith(rule):  # 判断是否是".sfx"结尾
                all.append(filename)
    return all

def file_insert(path, lenth,rule, string):
    lines = []
    with open(path, encoding='UTF-8') as f:
        lines = f.readlines()
    f.close()

    if lines != []:
        if rule in lines[lenth]:
            print('已经有了')
        else:
            with open(path, 'w', encoding='UTF-8') as f:
                print('插入行')
                lines.insert(lenth,string)
                f.writelines(lines)
            f.close()

htmlpath = get_files(r".", rule=".html")
for i in htmlpath:
    print(i)
    file_insert(i,7,r'referrer',r'<meta name="referrer" content="no-referrer" />')

实现效果

技术分享图片

技术分享图片

html使用网络图片防盗问题解决

原文:https://www.cnblogs.com/yywBlogW/p/11375694.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!