阴阳师高清壁纸下载,
横竖都有
import os
from html.parser import HTMLParser
import requests
import re
#splitStr='\\'
#path='E:\\me\\wallpaper\\yinyangshi'
splitStr='/'
path='/mnt/e/me/wallpaper/yinyangshi'
totalLine=0
class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
global totalLine
if tag == 'a':
for index,attr in enumerate(attrs):
if attr[0] == 'href' and '.jpg' in attr[1] :
#取后缀,做目录,先去掉文件类型
urlPath=re.sub('\.jpg.*$','',attr[1]).split('/')
dirPath = path + splitStr + str(urlPath[-1])
if not os.path.exists(dirPath):
os.makedirs(dirPath)
os.chdir(dirPath)
im = requests.get(attr[1])
fileName=urlPath[-6]+'_'+urlPath[-3]+'_'+urlPath[-2]+'_'+urlPath[-1]+'.jpg'
if not os.path.exists(dirPath+'/'+fileName):
open(fileName, 'wb').write(im.content) # 写入文件
print('已下载'+str(totalLine)+'个')
totalLine=totalLine+1
url='https://yys.163.com/media/picture.html'
im = requests.get(url) # 请求url
parser = MyHTMLParser()
parser.feed(im.text)