Skip to content

Instantly share code, notes, and snippets.

@lxfly2000
Last active September 20, 2023 03:54
Show Gist options
  • Save lxfly2000/05a4b52d82cf873fcb3cf54ce2fb986f to your computer and use it in GitHub Desktop.
Save lxfly2000/05a4b52d82cf873fcb3cf54ce2fb986f to your computer and use it in GitHub Desktop.
批量获取QQ表情预览图
# python 3.11
import os
import sys
from urllib import request
import urllib.error
# qqem <startid> <endid> [savepath]
if len(sys.argv)<2:
print("Usage: qqem <startid> [endid] [savepath]")
exit(1)
start_id=int(sys.argv[1])
end_id=start_id
save_path="."
if len(sys.argv)>=3:
end_id=int(sys.argv[2])
if len(sys.argv)>=4:
save_path=sys.argv[3]
if not os.path.exists(save_path):
os.mkdir(save_path)
def downloadFromURL(src_url,save_name):
print("下载\"%s\"到\"%s\"…"%(src_url,save_name))
try:
url_file=urllib.request.urlopen(src_url)
save_file=open(save_name,"wb")
save_file.write(url_file.read())
save_file.close()
except urllib.error.HTTPError as e:
print("下载失败:"+e.reason)
while start_id<=end_id:
downloadFromURL("https://imgcache.qq.com/club/item/parcel/img/parcel/%d/%d/200x200.png"%(start_id%10,start_id),
f"{save_path}/{start_id}.png")
start_id=start_id+1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment