很高兴能为您编写自动化脚本!以下是一个Python脚本,可以自动下载阿里的iconfont图标压缩包并解压到指定目录中:

import requests
import zipfile
import io
import os

# 阿里图标库页面链接
url = 'https://www.iconfont.cn/collections/detail?spm=a313x.7781069.1998910419.da358fa51&type=1'

# 下载链接的前缀和后缀
download_prefix = 'https:'
download_suffix = '/download?type=zip'

# 下载文件保存的路径
download_path = 'iconfont.zip'

# 解压后的文件保存的路径
extract_path = 'assets/fonts/iconfont'

# 发送请求获取页面内容
response = requests.get(url)
html = response.text

# 解析页面内容,提取下载链接
start_index = html.find('iconfont.cn') + len('iconfont.cn')
end_index = html.find('download?type=zip')
download_url = download_prefix + html[start_index:end_index] + download_suffix

# 下载压缩包
response = requests.get(download_url)
zip_file = zipfile.ZipFile(io.BytesIO(response.content))

# 解压文件到指定目录
zip_file.extractall(extract_path)

# 删除压缩包
os.remove(download_path)

print('下载并解压成功!')

使用方法:

  1. 将以上代码保存为一个Python文件,例如 download_iconfont.py

  2. 安装 requests 和 zipfile 库,可以使用以下命令安装:

    pip install requests
    pip install zipfile
    
  3. 运行脚本,可以使用以下命令:

    python download_iconfont.py
    

    脚本会自动下载阿里的iconfont图标压缩包并解压到指定目录中,解压后的文件可以在Flutter项目中直接使用。

自动化下载阿里iconfont图标并解压到Flutter项目

原文地址: https://www.cveoy.top/t/topic/lyI1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录