import sys
import requests
import re
import os
import threading
VNK = 'dbcbfa01'
data = '2020-07-21'
pages = 1
downloadPath = '/Users/lidong/Downloads/'
def get_pixiv(page):
user = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36',
}
url = 'https://api.pixivic.com/ranks?page=' + str(
page) + '&date=' + data + '&mode=day&pageSize=30'
response = requests.get(url, headers=user)
response.encoding = response.apparent_encoding
html = response.text
urls = re.findall('"original":"https://i.pximg.net/img-original/img/(..../../../../../../[0-9]*?_p0.*?g)"',
html)
names = re.findall('"artistId":.*?,"title":"(.*?)","type"', html)
ids = re.findall('"original":"https://i.pximg.net/img-original/img/..../../../../../../([0-9]*?)_p0.*?g"',
html)
for name, url, id in zip(names, urls, ids):
user = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362',
'Referer': 'https://pixivic.com/illusts/' + id + '?VNK=' + VNK,
'Accept': 'image/png, image/svg+xml, image/*; q=0.8, */*; q=0.5',
'Host': 'original.img.cheerfun.dev',
'Cache-Control': 'max-age=0',
'Accept-Encoding': 'gzip, deflate, br',
'Connection': 'Keep-Alive',
'Accept-Language': 'zh-CN'
}
url = 'https://original.img.cheerfun.dev/img-original/img/' + url
try:
name = name.replace('\\', '_').replace('?', '过滤')
except:
name = name
response = requests.get(url, headers=user)
if response.status_code == 200:
print('正在下载图片:' + name)
else:
print('错误代码' + response.status_code + '下载图片' + name + '失败!')
with open(downloadPath + name + '.jpg', 'wb') as f:
f.write(response.content)
if __name__ == '__main__':
if sys.getdefaultencoding() != 'utf-8':
reload(sys)
sys.setdefaultencoding('utf-8')
for page in [x for x in range(1, pages + 1)]:
threading.Thread(target=get_pixiv, args=(page,)).start()