最近想要自动下载一些東方project同人图,看了看几家同人图网站,最后想先拿yande.re试手,不用登陆,页面上也没有乱七八糟的广告混淆视听,而且图片普遍质量很高,以下是代码:
如果有想用的,直接修改tag,文件保存路径,页数就可以直接用了
import urllib
import urllib.request
import re
import time
import os
def delRepeat(a):
for x in a:
while a.count(x)>1:
del a[a.index(x)]
return a
def name(photo):
a = photo[33:]
b = a.replace("%20", "_").replace("%28", "(").replace("%29", ")")
return b
def save_img(img_url,file_name,file_path='D:\图片\从yande爬的图'):
#保存图片到磁盘文件夹 file_path中
try:
if not os.path.exists(file_path):
print ('文件夹',file_path,'不存在,重新建立')
os.makedirs(file_path)
file_suffix = os.path.splitext(img_url)[1] # 获得图片后缀
filename = '{}{}{}{}'.format(file_path,os.sep,file_na