当前位置:网站首页>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 :

边栏推荐
- Leasing cases of the implementation of the new regulations on the rental of jointly owned houses in Beijing
- Kubernetes带你从头到尾捋一遍
- [attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer
- Apache ant extension tutorial
- Byte practice surface longitude
- What is embedding (encoding an object into a low dimensional dense vector), NN in pytorch Principle and application of embedding
- 阿特拉斯atlas扭矩枪 USB通讯教程基于MTCOM
- [wechat applet] wxss template style
- What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
- [transform] [practice] use pytoch's torch nn. Multiheadattention to realize self attention
猜你喜欢

Vs+qt application development, set software icon icon

What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding

Centos7 deployment sentry redis (with architecture diagram, clear and easy to understand)

Kubernetes advanced training camp pod Foundation

Matplotlib drawing label cannot display Chinese problems
![[Yu Yue education] scientific computing and MATLAB language reference materials of Central South University](/img/83/922efb4f88843f1b7feaccf2b515b9.jpg)
[Yu Yue education] scientific computing and MATLAB language reference materials of Central South University

Kubernetes vous emmène du début à la fin
![[pytorch learning notes] datasets and dataloaders](/img/c0/9cd539caff34db3cccc44505bbe3c5.png)
[pytorch learning notes] datasets and dataloaders

Introduction to redis master-slave, sentinel and cluster mode
![[set theory] inclusion exclusion principle (complex example)](/img/9a/db5a75e27516378c31531773a8a221.jpg)
[set theory] inclusion exclusion principle (complex example)
随机推荐
Didi off the shelf! Data security is national security
Kubernetes advanced training camp pod Foundation
How does vs+qt set the software version copyright, obtain the software version and display the version number?
[ue4] Niagara's indirect draw
[transformer] Introduction - the original author of Harvard NLP presented the annotated transformer in the form of line by line implementation in early 2018
Use of Tex editor
4-33--4-35
什么是embedding(把物体编码为一个低维稠密向量),pytorch中nn.Embedding原理及使用
Yolov5 series (I) -- network visualization tool netron
MySQL reports an error: [error] mysqld: file '/ mysql-bin. 010228‘ not found (Errcode: 2 “No such file or directory“)
Stress test WebService with JMeter
4-29——4.32
What is label encoding? How to distinguish and use one hot encoding and label encoding?
Matlab r2011b neural network toolbox precautions
Search in the two-dimensional array of leetcode sword offer (10)
使用JMeter对WebService进行压力测试
Composite type (custom type)
C string format (decimal point retention / decimal conversion, etc.)
mysql innodb 存储引擎的特性—行锁剖析
Yolov5 advanced seven target tracking latest environment construction (II)