当前位置:网站首页>The markdown file obtains the pictures of the network and stores them locally and modifies the URL
The markdown file obtains the pictures of the network and stores them locally and modifies the URL
2022-07-03 15:14:00 【The fog always resolves】
This script aims to get all the pictures in the network in the specified file , And stored locally , And modify the url Point to local picture .
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : codekiller
# @Time : 2022/2/13 20:42
# @Email : [email protected]
# @File : MdImage.py
# @Description: Used for md Acquisition of pictures in files , Keep it locally , And modify it md file . It just needs to be modified ua And the location of the file
import re
import requests
import time
ua = Go to the browser to find
headers = {
"User-Agent": ua}
# The location of the file
file_dir = r'F:\md note \java\JVM\\'
file_n = 'test'
file_suffix = '.md'
fileName = file_dir+file_n+file_suffix
# Where to store pictures
img_tsrc = 'assets/'
img_src = file_dir + img_tsrc
with open(file=fileName, mode="r", encoding='utf-8') as f1:
# To count
s_count = 0
fail_count = 0
sus_count = 0
lines = f1.readlines()
for i in range(0, len(lines)):
url = re.findall('<img src="(.*?)"', lines[i], re.S)
if len(url)!=0:
url = url[0]
# Deal with local pictures
if len(re.findall(img_tsrc+'.*', url, re.S))!=0:
print(' The first ',i,' That's ok : For local pictures ')
s_count+=1
continue
# Get the time as the picture file name
timestamp = int(time.time())
image_name = str(time.strftime('%Y%m%d%H%M%S', time.localtime(timestamp)))+str(i)+".png"
# Ask for pictures
img = requests.get(url,headers=headers)
# Determine whether to obtain
if img.status_code != 200:
print(' The first ',i,' That's ok :','!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!',img.status_code)
fail_count+=1
continue
# Storage
target = open(img_src+image_name,'ab')
target.write(img.content)
target.close()
lines[i] = lines[i].replace(url,img_tsrc+image_name)
print(' The first ',i,' That's ok :',url+' Success turned into '+img_tsrc+image_name)
sus_count+=1
print('--- The local picture is :',s_count,' individual ---')
print('--- Failed to get :',fail_count,' individual ---')
print('--- Successfully converted to :',sus_count,' individual ---')
# To be processed cNames Write to a new file
fileName2 = file_dir+file_n+'- modify '+file_suffix
with open(file = fileName2,mode='w',encoding='utf-8') as f2:
f2.writelines(lines)
Console output :
An exclamation mark indicates that the conversion failed , Followed by the status code of the image ; Descriptions for local pictures do not need to be converted .
The effect of successful transformation :

边栏推荐
- Global and Chinese market of marketing automation 2022-2028: Research Report on technology, participants, trends, market size and share
- 什么是Label encoding?one-hot encoding ,label encoding两种编码该如何区分和使用?
- Global and Chinese market of transfer case 2022-2028: Research Report on technology, participants, trends, market size and share
- Explanation of time complexity and space complexity
- Remote server background hangs nohup
- 【pytorch学习笔记】Datasets and Dataloaders
- Série yolov5 (i) - - netron, un outil de visualisation de réseau
- 【Transform】【实践】使用Pytorch的torch.nn.MultiheadAttention来实现self-attention
- 4-20-4-23 concurrent server, TCP state transition;
- Yolov5系列(一)——网络可视化工具netron
猜你喜欢

4-33--4-35

Kubernetes帶你從頭到尾捋一遍

Byte practice plane longitude 2
![[transform] [NLP] first proposed transformer. The 2017 paper](/img/33/f639ab527d5adedfdc39f8d8117c3e.png)
[transform] [NLP] first proposed transformer. The 2017 paper "attention is all you need" by Google brain team

Matplotlib drawing label cannot display Chinese problems

解决pushgateway数据多次推送会覆盖的问题
![[pytorch learning notes] datasets and dataloaders](/img/c0/9cd539caff34db3cccc44505bbe3c5.png)
[pytorch learning notes] datasets and dataloaders

4-20-4-23 concurrent server, TCP state transition;

Série yolov5 (i) - - netron, un outil de visualisation de réseau
![[attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer](/img/9b/6ca8375ef8689a80d437665909ae30.png)
[attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer
随机推荐
阿特拉斯atlas扭矩枪 USB通讯教程基于MTCOM
Stress test WebService with JMeter
Leasing cases of the implementation of the new regulations on the rental of jointly owned houses in Beijing
【云原生训练营】模块七 Kubernetes 控制平面组件:调度器与控制器
What are the composite types of Blackhorse Clickhouse, an OLAP database recognized in the industry
Kubernetes - YAML文件解读
基础SQL教程
"Seven weapons" in the "treasure chest" of machine learning: Zhou Zhihua leads the publication of the new book "machine learning theory guide"
Use of Tex editor
. Net six design principles personal vernacular understanding, please correct if there is any error
How does vs+qt set the software version copyright, obtain the software version and display the version number?
Global and Chinese markets of AC electromechanical relays 2022-2028: Research Report on technology, participants, trends, market size and share
Yolov5 advanced seven target tracking latest environment construction (II)
Basic SQL tutorial
B2020 points candy
Redis cache penetration, cache breakdown, cache avalanche solution
Kubernetes will show you from beginning to end
Characteristics of MySQL InnoDB storage engine -- Analysis of row lock
There are links in the linked list. Can you walk three steps faster or slower
4-24--4-28