当前位置:网站首页>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 markets for infrared solutions (for industrial, civil, national defense and security applications) 2022-2028: Research Report on technology, participants, trends, market size and sh
- [transform] [practice] use pytoch's torch nn. Multiheadattention to realize self attention
- Use of Tex editor
- [Yu Yue education] scientific computing and MATLAB language reference materials of Central South University
- Devaxpress: range selection control rangecontrol uses
- Relationship between truncated random distribution and original distribution
- What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
- Remote server background hangs nohup
- Using TCL (tool command language) to manage Tornado (for VxWorks) can start the project
- Matlab r2011b neural network toolbox precautions
猜你喜欢
Remote server background hangs nohup
[engine development] rendering architecture and advanced graphics programming
redis缓存穿透,缓存击穿,缓存雪崩解决方案
视觉上位系统设计开发(halcon-winform)-4.通信管理
Open under vs2019 UI file QT designer flash back problem
4-33--4-35
5.4-5.5
运维体系的构建
[cloud native training camp] module 7 kubernetes control plane component: scheduler and controller
Kubernetes advanced training camp pod Foundation
随机推荐
Leetcode sword offer find the number I (nine) in the sorted array
【pytorch学习笔记】Transforms
在MapReduce中利用MultipleOutputs输出多个文件
Global and Chinese markets for indoor HDTV antennas 2022-2028: Research Report on technology, participants, trends, market size and share
What is machine reading comprehension? What are the applications? Finally someone made it clear
Can‘t connect to MySQL server on ‘localhost‘
Relationship between truncated random distribution and original distribution
Devaxpress: range selection control rangecontrol uses
Using TCL (tool command language) to manage Tornado (for VxWorks) can start the project
Global and Chinese markets for ionization equipment 2022-2028: Research Report on technology, participants, trends, market size and share
The state does not change after the assignment of El switch
Global and Chinese market of transfer case 2022-2028: Research Report on technology, participants, trends, market size and share
Use of Tex editor
Global and Chinese market of solder bars 2022-2028: Research Report on technology, participants, trends, market size and share
官网MapReduce实例代码详细批注
406. Reconstruct the queue according to height
Kubernetes帶你從頭到尾捋一遍
使用JMeter对WebService进行压力测试
Nppexec get process return code
[transform] [NLP] first proposed transformer. The 2017 paper "attention is all you need" by Google brain team