CSDN 自动上传图片并优化Markdown的图片显示

文章目录

    • 完整代码
    • 一、上传资源
    • 二、替换 MD 中的引用文件为在线链接
    • 参考

完整代码

完整代码由两个文件组成,upload.pymain.py,放在同一目录下运行 main.py 就好!

# upload.py
import requests  class UploadPic:  def __init__(self, cookie):  self.cookie = cookie  # 解析  self.file_path = ''  self.img_type = ''  # 两个请求体  self.upload_data = {}  self.csdn_data = {}  self.output_url = ''  def _get_file(self, file_path):  with open(file_path, mode='rb') as f:  binary_data = f.read()  return binary_data  def _upload_request(self):  headers = {  'accept': '*/*',  'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',  'content-type': 'application/json',  'cookie': self.cookie,  'origin': 'https://editor.csdn.net',  'priority': 'u=1, i',  'referer': 'https://editor.csdn.net/',  'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Microsoft Edge";v="126"',  'sec-ch-ua-mobile': '?0',  'sec-ch-ua-platform': '"Windows"',  'sec-fetch-dest': 'empty',  'sec-fetch-mode': 'cors',  'sec-fetch-site': 'same-site',  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0',  }  params = {  'type': 'blog',  'rtype': 'markdown',  'x-image-template': '',  'x-image-app': 'direct_blog',  'x-image-dir': 'direct',  'x-image-suffix': self.img_type,  }  url = 'https://imgservice.csdn.net/direct/v1.0/image/upload'  response = requests.get(url, params=params, headers=headers)  try:  self.upload_data = response.json()  except Exception as e:  return e  def _csdn_request(self):  headers = {  'Accept': 'application/json, text/javascript, */*; q=0.01',  'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',  'Connection': 'keep-alive',  'Origin': 'https://editor.csdn.net',  'Referer': 'https://editor.csdn.net/',  'Sec-Fetch-Dest': 'empty',  'Sec-Fetch-Mode': 'cors',  'Sec-Fetch-Site': 'cross-site',  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0',  'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Microsoft Edge";v="126"',  'sec-ch-ua-mobile': '?0',  'sec-ch-ua-platform': '"Windows"',  }  files = {  'key': (None, self.upload_data['data']['filePath']),  'policy': (None, self.upload_data['data']['policy']),  'OSSAccessKeyId': (None, self.upload_data['data']['accessId']),  'success_action_status': (None, '200'),  'signature': (None, self.upload_data['data']['signature']),  'callback': (None, self.upload_data['data']['callbackUrl']),  'file': (f'image.{self.img_type}', self._get_file(self.file_path), f'image/{self.img_type}'),  }  url = 'https://csdn-img-blog.oss-cn-beijing.aliyuncs.com/'  response = requests.post(url, headers=headers, files=files)  try:  self.csdn_data = response.json()  self.output_url = self.csdn_data['data']['imageUrl']  except Exception as e:  return e  def upload_image(self, file_path):  self.file_path = file_path  self.img_type = self.file_path.split('.')[-1]  exception_1 = self._upload_request()  assert exception_1 is None, exception_1  exception_2 = self._csdn_request()  assert exception_2 is None, exception_2  return self.output_url  if __name__ == '__main__':  cookie = '' # 输入你的cookie  upload = UploadPic(cookie)  output_url = upload.upload_image('')  #输入你需要上传的文件位置print(output_url)
# main.py
import os  
import re  
from pathlib import Path  
from rich.progress import track  
from upload import UploadPic  class CSDNTransform:  def __init__(self, upload:UploadPic, file_path, walk_path='C:/Users/Administrator/Documents/Obsidian Vault/'):  self.upload = upload  self.file_path = file_path  self.walk_path = walk_path  self.markdown_text = ''  self.image_lst = []  self.posterior_image_lst = []  self.image_2_url_dic = {}  def _get_markdown_text(self):  with open(self.file_path, mode='r', encoding='utf-8') as f:  markdown_text = f.read()  self.markdown_text = markdown_text  def _process_markdown_text(self):  image_lst = re.findall(r'(!\[\[.*]])', self.markdown_text)  posterior_image_lst = [item[3:-2] for item in image_lst]  self.image_lst = image_lst  self.posterior_image_lst = posterior_image_lst  def _get_target_image_path(self, target_path):  for root, floders, files in os.walk(self.walk_path):  for file in files:  if file == target_path:  return str(Path(root) / file)  def _get_the_url_of_image(self, image_path):  image_url = self.upload.upload_image(image_path)  return image_url  def get_the_urls(self):  self._get_markdown_text()  self._process_markdown_text()  not_exist_image_index = []  for ix, (origin_image, target_path) in track(enumerate(zip(self.image_lst, self.posterior_image_lst))):  image_path = self._get_target_image_path(target_path)  if image_path is not None:  image_url = self._get_the_url_of_image(image_path)  self.image_2_url_dic[origin_image] = image_url  else:  not_exist_image_index.append(ix)  # 清楚掉需要删除的index  num = 0  for ix in not_exist_image_index:  del self.image_lst[ix-num]  del self.posterior_image_lst[ix-num]  num += 1  def _the_transform_data_from(self, image_url):  data_form = f"""\n<div align=center><img src="{image_url}"></div>\n"""  return data_form  def _save_markdown_text(self, output_file='markdown_processed.txt'):  with open(output_file, mode='w', encoding='utf-8') as f:  f.write(self.markdown_text)  def get_transform(self):  self.get_the_urls()  # Judge the length  assert len(self.image_lst) == len(self.image_2_url_dic), f"上传成功{len(self.image_2_url_dic)}张图片,总共有{len(self.image_lst)}张图片"  for origin_image, image_url in self.image_2_url_dic.items():  self.markdown_text = self.markdown_text.replace(origin_image, self._the_transform_data_from(image_url))  self._save_markdown_text()if __name__ == '__main__':  cookie = ''  # 输入你的cookiefile_path = ''  # 输入你要转换的markdown文件地址upload = UploadPic(cookie)  transform = CSDNTransform(upload, file_path)  markdown_text = transform.get_transform()# 修改后的 Markdown 在当前目录的 markdown_processed.txt 文件中

一、上传资源

首先我们解析 CSDN 上传请求,这里随便上传一张图片,观察请求;

请求由三部分组成,分别是:1. 获取存储位置和签名验证信息;2. 利用签名等验证信息上传文件;3. 获取文件信息并显示;

仔细观察两个请求,upload 请求是 GET ,csdn 请求是 POST,其结果很明显 csdn 请求是主体,仔细观察 csdn 的参数,可以所有参数都可以利用 upload 的返回结果得到;

那么接下来我们开始构造 upload 请求

import requestsheaders = {'accept': '*/*','accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6','content-type': 'application/json','cookie': '', # 输入自己的cookies'origin': 'https://editor.csdn.net','priority': 'u=1, i','referer': 'https://editor.csdn.net/','sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Microsoft Edge";v="126"','sec-ch-ua-mobile': '?0','sec-ch-ua-platform': '"Windows"','sec-fetch-dest': 'empty','sec-fetch-mode': 'cors','sec-fetch-site': 'same-site','user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0',
}params = {'type': 'blog','rtype': 'markdown','x-image-template': '','x-image-app': 'direct_blog','x-image-dir': 'direct','x-image-suffix': 'png',
}url = 'https://imgservice.csdn.net/direct/v1.0/image/upload'
response = requests.get(url, params=params, headers=headers)# 获得数据
upload_data = response.json()

得到 json 内容如下,通过比较该内容下 expire 和 time 库下的 time.time() * 1000,再根据英文名可以推断,expire 表示的是上传文件这一请求的失效时间,即 csdn 请求的最晚成功时间;

{'code': 200,'data': {'accessId': 'LTAI5tK31AXMAqwzaX1wn4hH','callbackUrl': 'eyJjYWxsYmFja0JvZHlUeXBlIjoiYXBwbGljYXRpb24vanNvbiIsImNhbGxiYWNrVXJsIjoiaHR0cHM6Ly9pbWdzZXJ2aWNlLmNzZG4ubmV0L2RpcmVjdC92MS4wL2ltYWdlL2NhbGxiYWNrIiwiY2FsbGJhY2tCb2R5Ijoie1wiZmlsZVBhdGhcIjpcImRpcmVjdC9jN2VlYWNjZjU2ZDM0MzM3OWQ2Yjk4ZmYwNGYyZWFjNS5wbmdcIixcImlzQXVkaXRcIjoxLFwieC1pbWFnZS1hcHBcIjpcImRpcmVjdF9ibG9nXCIsXCJ0eXBlXCI6XCJibG9nXCIsXCJ1cmxNZDVcIjpcImM3ZWVhY2NmNTZkMzQzMzc5ZDZiOThmZjA0ZjJlYWM1XCIsXCJydHlwZVwiOlwibWFya2Rvd25cIixcImhvc3RuYW1lXCI6XCJodHRwczovL2ltZy1ibG9nLmNzZG5pbWcuY24vXCIsXCJzaXplXCI6XCIke3NpemV9XCIsXCJ4LWltYWdlLWRpclwiOlwiZGlyZWN0XCIsXCJ3aWR0aFwiOlwiJHtpbWFnZUluZm8ud2lkdGh9XCIsXCJ4LWltYWdlLXN1ZmZpeFwiOlwicG5nXCIsXCJ1c2VybmFtZVwiOlwibTBfNzI5NDczOTBcIixcImhlaWdodFwiOlwiJHtpbWFnZUluZm8uaGVpZ2h0fVwifSJ9','dir': 'direct','expire': '1718611892700','filePath': 'direct/c7eeaccf56d343379d6b98ff04f2eac5.png','host': 'https://csdn-img-blog.oss-cn-beijing.aliyuncs.com','policy': 'eyJleHBpcmF0aW9uIjoiMjAyNC0wNi0xN1QwODoxMTozMi43MDBaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwXSxbInN0YXJ0cy13aXRoIiwiJGtleSIsImRpcmVjdC9jN2VlYWNjZjU2ZDM0MzM3OWQ2Yjk4ZmYwNGYyZWFjNS5wbmciXV19','signature': '2hRKp5YO3epBJe5+Qt7Ngi7P/y4='},'message': None,'msg': 'success'}

下面利用 upload 得到的请求来构造 csdn 请求;

import requests
from requests_toolbelt.multipart.encoder import MultipartEncoderdef get_file(file_path):"""获取文件的二进制数据"""with open(file_path, mode='rb') as f:binary_data = f.read()return binary_dataheaders = {'Accept': 'application/json, text/javascript, */*; q=0.01','Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6','Connection': 'keep-alive','Origin': 'https://editor.csdn.net','Referer': 'https://editor.csdn.net/','Sec-Fetch-Dest': 'empty','Sec-Fetch-Mode': 'cors','Sec-Fetch-Site': 'cross-site','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0','sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Microsoft Edge";v="126"','sec-ch-ua-mobile': '?0','sec-ch-ua-platform': '"Windows"',
}success_action_status = '200'# upload 请求中获取到的数据
key = upload_data['data']['filePath']
policy = upload_data['data']['policy']
OSSAccessKeyId = upload_data['data']['accessId']
signature = upload_data['data']['signature']
callback = upload_data['data']['callbackUrl']# 上传的图片位置,
file = get_file('') # 输入需要上传文件的位置files = {'key': (None, key),'policy': (None, policy),'OSSAccessKeyId': (None, OSSAccessKeyId),'success_action_status': (None, '200'),'signature': (None, signature),'callback': (None, callback),'file': ('image.png', file, 'image/png'),
}url = 'https://csdn-img-blog.oss-cn-beijing.aliyuncs.com/'
response = requests.post(url, headers=headers, files=files)print(response.text)

得到 Json 数据如下

{'code': 200,'data': {'hostname': 'https://img-blog.csdnimg.cn/','imageUrl': 'https://img-blog.csdnimg.cn/direct/97c5610606c140afb474800403140ea3.png','width': '1138','targetObjectKey': 'direct/97c5610606c140afb474800403140ea3.png','x-image-suffix': 'png','height': '239'},'msg': 'success'}

在其中 imageUrl 就表示上传的图片地址,同时,图片格式有许多种,面对不同的图片格式,在尝试观察后发现只需要修改 upload 请求中 parms 中的 x-image-suffixcsdn 请求中 files 中的 file

整合得到完整上传类如下:

import requests  class UploadPic:  def __init__(self, cookie):  self.cookie = cookie  # 解析  self.file_path = ''  self.img_type = ''  # 两个请求体  self.upload_data = {}  self.csdn_data = {}  self.output_url = ''  def _get_file(self, file_path):  with open(file_path, mode='rb') as f:  binary_data = f.read()  return binary_data  def _upload_request(self):  headers = {  'accept': '*/*',  'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',  'content-type': 'application/json',  'cookie': self.cookie,  'origin': 'https://editor.csdn.net',  'priority': 'u=1, i',  'referer': 'https://editor.csdn.net/',  'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Microsoft Edge";v="126"',  'sec-ch-ua-mobile': '?0',  'sec-ch-ua-platform': '"Windows"',  'sec-fetch-dest': 'empty',  'sec-fetch-mode': 'cors',  'sec-fetch-site': 'same-site',  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0',  }  params = {  'type': 'blog',  'rtype': 'markdown',  'x-image-template': '',  'x-image-app': 'direct_blog',  'x-image-dir': 'direct',  'x-image-suffix': self.img_type,  }  url = 'https://imgservice.csdn.net/direct/v1.0/image/upload'  response = requests.get(url, params=params, headers=headers)  try:  self.upload_data = response.json()  except Exception as e:  return e  def _csdn_request(self):  headers = {  'Accept': 'application/json, text/javascript, */*; q=0.01',  'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',  'Connection': 'keep-alive',  'Origin': 'https://editor.csdn.net',  'Referer': 'https://editor.csdn.net/',  'Sec-Fetch-Dest': 'empty',  'Sec-Fetch-Mode': 'cors',  'Sec-Fetch-Site': 'cross-site',  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0',  'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Microsoft Edge";v="126"',  'sec-ch-ua-mobile': '?0',  'sec-ch-ua-platform': '"Windows"',  }  files = {  'key': (None, self.upload_data['data']['filePath']),  'policy': (None, self.upload_data['data']['policy']),  'OSSAccessKeyId': (None, self.upload_data['data']['accessId']),  'success_action_status': (None, '200'),  'signature': (None, self.upload_data['data']['signature']),  'callback': (None, self.upload_data['data']['callbackUrl']),  'file': (f'image.{self.img_type}', self._get_file(self.file_path), f'image/{self.img_type}'),  }  url = 'https://csdn-img-blog.oss-cn-beijing.aliyuncs.com/'  response = requests.post(url, headers=headers, files=files)  try:  self.csdn_data = response.json()  self.output_url = self.csdn_data['data']['imageUrl']  except Exception as e:  return e  def upload_image(self, file_path):  self.file_path = file_path  self.img_type = self.file_path.split('.')[-1]  exception_1 = self._upload_request()  assert exception_1 is None, exception_1  exception_2 = self._csdn_request()  assert exception_2 is None, exception_2  return self.output_url  if __name__ == '__main__':  cookie = '' # 输入你的cookie  upload = UploadPic(cookie)  output_url = upload.upload_image('')  #输入你需要上传的文件位置print(output_url)

二、替换 MD 中的引用文件为在线链接

首先,肯定是整体替换而不是单个替换,因此我们的流程为:1. 上传所有文件,直到所有的文件都上传成功;2. 替换所有文件;

首先提取出 Markdown 中所有的图片信息,一般来说图片信息都在两个中括号之间 ![[ img_pic ]],使用 re 正则提取,代码如下;

import refile_path = 'C:/Users/Administrator/Documents/Obsidian Vault/UE开发/My FirstGame Tutorial.md'with open(file_path, mode='r', encoding='utf-8') as f:markdown_text = f.read()image_lst = re.findall(r'(!\[\[.*\]\])', markdown_text)
posterior_image_lst = [item[3:-2] for item in image_lst]

提取出所有的 img_pic 后,我们需要在根目录下寻找文件,一般来说在 Markdown 中文件名是不重复的;

import os
from pathlib import Pathdef get_target_image_path(target_path):walk_path = 'C:/Users/Administrator/Documents/Obsidian Vault/'for root, floders, files in os.walk(walk_path):for file in files:if file == target_path:return Path(root) / fileget_target_image_path(posterior_image_lst[0])

获取到了绝对位置后,我们可以将图片上传,在检查图片全部都上传完毕后,我们就可以替换 ![[ img_pic ]]

import os  
import re  
import requests  
from pathlib import Path  
from rich.progress import track  class UploadPic:  def __init__(self, cookie):  self.cookie = cookie  # 解析  self.file_path = ''  self.img_type = ''  # 两个请求体  self.upload_data = {}  self.csdn_data = {}  self.output_url = ''  def _get_file(self, file_path):  with open(file_path, mode='rb') as f:  binary_data = f.read()  return binary_data  def _upload_request(self):  headers = {  'accept': '*/*',  'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',  'content-type': 'application/json',  'cookie': self.cookie,  'origin': 'https://editor.csdn.net',  'priority': 'u=1, i',  'referer': 'https://editor.csdn.net/',  'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Microsoft Edge";v="126"',  'sec-ch-ua-mobile': '?0',  'sec-ch-ua-platform': '"Windows"',  'sec-fetch-dest': 'empty',  'sec-fetch-mode': 'cors',  'sec-fetch-site': 'same-site',  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0',  }  params = {  'type': 'blog',  'rtype': 'markdown',  'x-image-template': '',  'x-image-app': 'direct_blog',  'x-image-dir': 'direct',  'x-image-suffix': self.img_type,  }  url = 'https://imgservice.csdn.net/direct/v1.0/image/upload'  response = requests.get(url, params=params, headers=headers)  try:  self.upload_data = response.json()  except Exception as e:  return e  def _csdn_request(self):  headers = {  'Accept': 'application/json, text/javascript, */*; q=0.01',  'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',  'Connection': 'keep-alive',  'Origin': 'https://editor.csdn.net',  'Referer': 'https://editor.csdn.net/',  'Sec-Fetch-Dest': 'empty',  'Sec-Fetch-Mode': 'cors',  'Sec-Fetch-Site': 'cross-site',  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0',  'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Microsoft Edge";v="126"',  'sec-ch-ua-mobile': '?0',  'sec-ch-ua-platform': '"Windows"',  }  files = {  'key': (None, self.upload_data['data']['filePath']),  'policy': (None, self.upload_data['data']['policy']),  'OSSAccessKeyId': (None, self.upload_data['data']['accessId']),  'success_action_status': (None, '200'),  'signature': (None, self.upload_data['data']['signature']),  'callback': (None, self.upload_data['data']['callbackUrl']),  'file': (f'image.{self.img_type}', self._get_file(self.file_path), f'image/{self.img_type}'),  }  url = 'https://csdn-img-blog.oss-cn-beijing.aliyuncs.com/'  response = requests.post(url, headers=headers, files=files)  try:  self.csdn_data = response.json()  self.output_url = self.csdn_data['data']['imageUrl']  except Exception as e:  return e  def upload_image(self, file_path):  self.file_path = file_path  self.img_type = self.file_path.split('.')[-1]  exception_1 = self._upload_request()  assert exception_1 is None, exception_1  exception_2 = self._csdn_request()  assert exception_2 is None, exception_2  return self.output_url  class CSDNTransform:  def __init__(self, upload:UploadPic, file_path, walk_path='C:/Users/Administrator/Documents/Obsidian Vault/'):  self.upload = upload  self.file_path = file_path  self.walk_path = walk_path  self.markdown_text = ''  self.image_lst = []  self.posterior_image_lst = []  self.image_2_url_dic = {}  def _get_markdown_text(self):  with open(self.file_path, mode='r', encoding='utf-8') as f:  markdown_text = f.read()  self.markdown_text = markdown_text  def _process_markdown_text(self):  image_lst = re.findall(r'(!\[\[.*]])', self.markdown_text)  posterior_image_lst = [item[3:-2] for item in image_lst]  self.image_lst = image_lst  self.posterior_image_lst = posterior_image_lst  def _get_target_image_path(self, target_path):  for root, floders, files in os.walk(self.walk_path):  for file in files:  if file == target_path:  return str(Path(root) / file)  def _get_the_url_of_image(self, image_path):  image_url = self.upload.upload_image(image_path)  return image_url  def get_the_urls(self):  self._get_markdown_text()  self._process_markdown_text()  not_exist_image_index = []  for ix, (origin_image, target_path) in track(enumerate(zip(self.image_lst, self.posterior_image_lst))):  image_path = self._get_target_image_path(target_path)  if image_path is not None:  image_url = self._get_the_url_of_image(image_path)  self.image_2_url_dic[origin_image] = image_url  else:  not_exist_image_index.append(ix)  # 清楚掉需要删除的index  num = 0  for ix in not_exist_image_index:  del self.image_lst[ix-num]  del self.posterior_image_lst[ix-num]  num += 1  def _the_transform_data_from(self, image_url):  data_form = f"""\n<div align=center><img src="{image_url}"></div>\n"""  return data_form  def _save_markdown_text(self, output_file='markdown_processed.txt'):  with open(output_file, mode='w', encoding='utf-8') as f:  f.write(self.markdown_text)  def get_transform(self):  self.get_the_urls()  # Judge the length  assert len(self.image_lst) == len(self.image_2_url_dic), f"上传成功{len(self.image_2_url_dic)}张图片,总共有{len(self.image_lst)}张图片"  for origin_image, image_url in self.image_2_url_dic.items():  self.markdown_text = self.markdown_text.replace(origin_image, self._the_transform_data_from(image_url))  self._save_markdown_text()if __name__ == '__main__':  cookie = ''  # 输入你的cookiefile_path = ''  # 输入你要转换的markdown文件地址upload = UploadPic(cookie)  transform = CSDNTransform(upload, file_path)  markdown_text = transform.get_transform()# 修改后的 Markdown 在当前目录的 markdown_processed.txt 文件中

参考

requests库post请求参数data、json和files的使用_requests post data-CSDN博客
HTTP协议之multipart/form-data请求分析_http form-data请求-CSDN博客

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/357050.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2-13 基于matlab的电力负荷预测

基于matlab的电力负荷预测&#xff0c;论文阐述了负荷预测的应用研究现状&#xff0c;概括了负荷预测的特点及其影响因素&#xff0c;归纳了短期负荷预测的常用方法&#xff0c;并分析了各种方法的优劣&#xff1b;采用最小二乘支持向量机&#xff08;LSSVM&#xff09;模型&am…

docker desktop for mac os如何使用本地代理

在macbook上弄了个代理&#xff0c;然后按照网上所说的去配代理 然后测试下 docker pull busybox 结果无反应&#xff0c;超时。我去&#xff01;&#xff01;&#xff01; 鼓捣了半天&#xff0c;看了docker官网&#xff0c;问了chatgpt &#xff0c;按照它们所说的试了下也没…

告别卡顿,迎接流畅!你的mac电脑清洁利器CleanMyMac一键轻松解决所有问题!

亲爱的CSDN家人们&#xff0c;今天要安利的是一个让无数Mac用户从“抓狂”到“惊喜连连”的小神器—CleanMyMac&#xff01;&#x1f4ab; 如果你还在为电脑的缓慢启动、存储空间告急和莫名其妙的卡顿烦恼&#xff0c;那请跟我一起看看它如何成为你的数字世界里的救星&#xff…

阿里云发送验证码流程

目录 1. 阿里云短信服务简介 2. 阿里云验证码发送流程 2.1 申请阿里云短信服务 2.2 短信模板及阿里云秘钥 1.开发者可以在自己的应用程序中集成短信发送功能。绑定发起测试的手机号&#xff0c;需要绑定的手机号才能成功发送验证码&#xff0c;其他的用户手机号发送的验…

class中的溢出滑动效果

效果图&#xff1a; 代码&#xff1a; <!DOCTYPE html> <html><head><meta charset"utf-8"><title></title></head><style>*{margin: 0;padding: 0;}.frame-pages{width: 30%;height: 60px;display: flex;justify…

【MySQL】事务一

事务一 1.什么是事务2.为什么会存在事务3.事务的版本支持4.事务的提交方式5.事务常见操作方式6.事务隔离级别6.1读未提交【Read Uncommitted】6.2读提交【Read Committed】6.3可重复读【Repeatable Read】6.4串行化【serializable】 点赞&#x1f44d;&#x1f44d;收藏&#x…

6/22 第四周 python操作word

学习到了word有四个段落&#xff0c;都可以通过python来操作。 并且课程的体系&#xff0c;只是一个启蒙&#xff0c;需要在公司的项目中熟悉&#xff0c;从而具备专项测试的能力。 后续每天的学习笔记也需要侧重于理解的部分。

LangChain:如何高效管理 LLM 聊天历史记录?

LangChain 团队发布了一篇关于使用 Dragonfly DB 来有效管理 LangChain 应用程序聊天历史记录的教程。 该教程旨在解决用户在使用 LangChain 应用程序时普遍遇到的一个问题&#xff1a;如何高效地管理聊天历史记录。 LangChain 团队在推文中强调了 Dragonfly DB 在管理聊天历…

华为RH2288 V3安装 Linux 系统,安装过程心得

带着U盘&#xff0c;怀着激动的心情进入机房安装操作系统&#xff0c;结果没有显示器和键盘鼠标&#xff0c;傻眼了。 作为过来人&#xff0c;温馨提醒&#xff0c;进入机房前记得先打听&#xff0c;准备好这些&#xff1a;机房房间号、机柜编号、物理机编号、键盘、鼠标、显示…

Unity中实现ScrollRect 滚动定位到视口内

Demo链接: https://download.csdn.net/download/qq_41973169/89446832https://download.csdn.net/download/qq_41973169/89446832 一、前言 Unity版本:2020.1.x 在Unity游戏开发中&#xff0c;滚动视图中元素的定位是一个常见需求。为了解决这个问题&#xff0c;我们可以编…

不到3毛钱的SOT23和SOT89封装18V耐压低功耗高PSRR高精度LDO稳压芯片ME6231电流0.5A电压3.3V和1.8V

前言 SOT23-5封装ME6231外观和丝印 一款国产LDO&#xff0c;某些场合&#xff0c;要把1117扔了吧&#xff0c;SOT23封装&#xff0c;虽然不是最小&#xff0c;但也是够小的了。 参考价格&#xff1a;约0.25元 概述 ME6231 系列是以 CMOS 工艺制造的 18V 耐压、低功耗、高 PSR…

OpenCV中的圆形标靶检测——findCirclesGrid()(三)

前面说到cv::findCirclesGrid2()内部先使用SimpleBlobDetector进行圆斑检测,然后使用CirclesGridClusterFinder算法类执行基于层次聚类的标靶检测。如下图所示,由于噪声的影响,SimpleBlobDetector检出的标靶可能包含噪声。 而CirclesGridClusterFinder算法类会执行基…

驾校在线考试系统源码 手机+PC+平板自适应

Thinkphp在线考题源码 驾校在线考试系统 手机PC平板 自适应&#xff0c;机动车驾驶培训学校驾校类网站源码带手机端 运行环境&#xff1a;phpmysql 内附安装说明 驾校在线考试系统源码 手机PC平板自适应

微信小程序毕业设计-小区疫情防控系统项目开发实战(附源码+论文)

大家好&#xff01;我是程序猿老A&#xff0c;感谢您阅读本文&#xff0c;欢迎一键三连哦。 &#x1f49e;当前专栏&#xff1a;微信小程序毕业设计 精彩专栏推荐&#x1f447;&#x1f3fb;&#x1f447;&#x1f3fb;&#x1f447;&#x1f3fb; &#x1f380; Python毕业设计…

2024/6/22 英语每日一段

France is the only country in Europe with an EPR that covers the textile industry. Critics say the policy does little for “end-of-line” countries such as Ghana because the fee paid by clothing producers is low at just €0.06 for each item, and the funds …

centos7系统使用docker-compose安装部署jenkins

CentOS7系统使用docker-compose安装部署jenkins&#xff0c;并实现前后端自动构建 记录一次工作中部署jenkins的真实经历&#xff0c;总结了相关经验 1.准备环境 1.java 由于最新的jenkins需要jdk11以上才能支持&#xff0c;而系统里的jdk是1.8的&#xff0c;因此等jenkins安…

C语言| 数组的折半查找

数组的折半查找 折半查找&#xff1a;在已经排好序的一组数据中快速查找数据。 先排序&#xff0c;再使用折半查找。 【折半查找的运行过程】 1 存储数组下标 low最小的下标&#xff0c;mid中间的下标&#xff0c; high最大的下标 2 key存放查找的值&#xff0c;每一次对比后…

提升研发效率:三品PLM解决方案在汽车汽配行业的实践

随着全球汽车市场的快速发展&#xff0c;中国汽车汽配行业迎来了前所未有的发展机遇。然而&#xff0c;在这一过程中&#xff0c;企业也面临着诸多挑战&#xff0c;如研发能力的提升、技术资料管理的复杂性、以及跨部门协作的困难等。为了应对这些挑战&#xff0c;三品产品生命…

IDEA快速入门02-快速入门

二、快速入门 2.1 打开IDEA,点击New一个项目 入口&#xff0c;依次打开 File -> New -> Project。 2.2 使用Spring Initializr方式构建Spring Boot项目 2.3 设置项目所属组、项目名称、java版本等 2.4 选择SpringBoot版本及依赖组件 点击Create进行创建。 2.6 创建成…

【一】【算法】经典树状数组和并查集,详细解析,初步认识,【模板】树状数组 1,树状数组并查集

【模板】树状数组 1 题目描述 如题&#xff0c;已知一个数列&#xff0c;你需要进行下面两种操作&#xff1a; 将某一个数加上 x x x 求出某区间每一个数的和 输入格式 第一行包含两个正整数 n , m n,m n,m&#xff0c;分别表示该数列数字的个数和操作的总个数。 第二…