437 words
2 minutes
将astro的md格式博客转为吾爱破解[md]博客,图片地址转换
2025-05-02
No Tags

图片地址转换#

原理:先在本地写好,然后push到你的网站,等网站更新后,通过写爬虫程序获取到图片的地址,然后再另存为一份md文件,更新图片地址,最后直接全选复制黏贴到吾爱破解发帖的地方,格式选择MarkDown发帖工具。

从个人网站里随便打开一个博客,看img的地址。可以发现它主要是后面多了这坨东西,然后改一下后缀就行

image-20250502120748049

在页面源代码里搜这个关键字

image-20250502122204975

因为本地里图片有关键字(如图),所以提取本地image的关键字在页面源代码里用正则/xpath搜索。

image-20250502123046738

或者直接提取assets里的图片名字,这个比较方便,我选此法

image-20250502123646639

import os

# Specify the directory path
directory_path = './fuckCSDN.assets'

# List all files in the directory
file_names = os.listdir(directory_path)

# Print the file names
for file_name in file_names:
    print(file_name)

注意:不要ctrl+S 把页面源代码保存到本地分析,我的不知道怎么回事一直提取不到img,直到用requests发请求再解析才能。

def extract_src(img_alt):
    # To extract the src attribute from the <img> node 
    # with the specific alt attribute value passed as img_alt
    src = tree.xpath(f'//img[@alt="{img_alt}"]/@src')[0]
    return src

获取到src后,更改本地md文件(另存为)

![image-20250502123646639](astromd252pj.assets/image-20250502123646639.png)改为

![image-20250502123646639](https://zycreverse.netlify.app/_astro/image-20250502123646639.xxxxxxxx.webp)

预览效果如下

image-20250502133514634

完整代码#

teapot-4l8
/
astromd252pj
Waiting for api.github.com...
00K
0K
0K
Waiting...

图片批量+水印#

另外最近发现一些零零碎碎的网站会偷吾爱破解的帖子,吾爱破解的图片有水印,但个人网站的图片则没有,遂想给个人网站添加一个自动加水印的功能。

其它细节#

  • 在文件前后加上**[md]**标签 [/md]
  • 仓库卡片转url
  • 代码发帖
将astro的md格式博客转为吾爱破解[md]博客,图片地址转换
https://zycreverse.netlify.app/posts/astromd252pj/
Author
会写点代码的本子画手
Published at
2025-05-02