|
|
@ -9,9 +9,9 @@ import sys |
|
|
|
from datetime import datetime |
|
|
|
from datetime import datetime |
|
|
|
import os |
|
|
|
import os |
|
|
|
import zipfile |
|
|
|
import zipfile |
|
|
|
import logging.config |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from PixivSearch.model import config |
|
|
|
from PixivSearch.model import config |
|
|
|
|
|
|
|
from PixivSearch.settings import logger |
|
|
|
|
|
|
|
|
|
|
|
headers = { |
|
|
|
headers = { |
|
|
|
'X-Requested-With': 'XMLHttpRequest', |
|
|
|
'X-Requested-With': 'XMLHttpRequest', |
|
|
@ -21,8 +21,7 @@ headers = { |
|
|
|
|
|
|
|
|
|
|
|
lock = threading.Lock() # 多线程全局资源锁 |
|
|
|
lock = threading.Lock() # 多线程全局资源锁 |
|
|
|
total = 1 |
|
|
|
total = 1 |
|
|
|
logging.config.fileConfig('PixivSearch/logging.conf') |
|
|
|
|
|
|
|
logger = logging.getLogger('file') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_cookies(): |
|
|
|
def get_cookies(): |
|
|
|
_cookies = {} |
|
|
|
_cookies = {} |
|
|
@ -33,8 +32,6 @@ def get_cookies(): |
|
|
|
return _cookies |
|
|
|
return _cookies |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def crawl(url): |
|
|
|
def crawl(url): |
|
|
|
global total |
|
|
|
global total |
|
|
|
req = requests.get(url, headers=headers, cookies=get_cookies()).text |
|
|
|
req = requests.get(url, headers=headers, cookies=get_cookies()).text |
|
|
@ -44,10 +41,12 @@ def crawl(url): |
|
|
|
with lock: |
|
|
|
with lock: |
|
|
|
nodes.append(imageNode) |
|
|
|
nodes.append(imageNode) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_urls(search, page): |
|
|
|
def get_urls(search, page): |
|
|
|
fmt = 'https://www.pixiv.net/search.php?word={}&order=date_d&p={}' |
|
|
|
fmt = 'https://www.pixiv.net/search.php?word={}&order=date_d&p={}' |
|
|
|
return [fmt.format(search, p) for p in range(1, page)] |
|
|
|
return [fmt.format(search, p) for p in range(1, page)] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_Img(params): |
|
|
|
def get_Img(params): |
|
|
|
params[1]['imgUrl'] = 'https://i.pximg.net/img-original/img/' + params[1]['url'][-46:-15] |
|
|
|
params[1]['imgUrl'] = 'https://i.pximg.net/img-original/img/' + params[1]['url'][-46:-15] |
|
|
|
|
|
|
|
|
|
|
@ -64,13 +63,17 @@ def get_Img(params): |
|
|
|
logger.error('无法下载图片:%s' % (params[1]['illustTitle'])) |
|
|
|
logger.error('无法下载图片:%s' % (params[1]['illustTitle'])) |
|
|
|
return |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
logger.info('下载图片:"%s"到%s'%(params[1]['illustTitle'],os.getcwd().replace('\\','/')+'/'+imgPath+params[1]['illustId']+suffix)) |
|
|
|
logger.info('下载图片:"%s"到%s' % ( |
|
|
|
|
|
|
|
params[1]['illustTitle'], os.getcwd().replace('\\', '/') + '/' + imgPath + params[1]['illustId'] + suffix)) |
|
|
|
f = open(imgPath + params[1]['illustId'] + suffix, 'wb') # 写入多媒体文件要 b 这个参数 |
|
|
|
f = open(imgPath + params[1]['illustId'] + suffix, 'wb') # 写入多媒体文件要 b 这个参数 |
|
|
|
f.write(s.content) # 多媒体文件要是用conctent |
|
|
|
f.write(s.content) # 多媒体文件要是用conctent |
|
|
|
f.close() |
|
|
|
f.close() |
|
|
|
|
|
|
|
|
|
|
|
params[1]['localName'] = params[1]['illustId'] + suffix |
|
|
|
params[1]['localName'] = params[1]['illustId'] + suffix |
|
|
|
logger.info('排行第%d名,收藏数%d,标题:%s,标签:%s,(%s)前投稿,链接:%s'%(params[0],params[1]['bookmarkCount'],params[1]['illustTitle'], ','.join(params[1]['tags']),'',params[1]['imgUrl'])) |
|
|
|
logger.info('排行第%d名,收藏数%d,标题:%s,标签:%s,(%s)前投稿,链接:%s' % ( |
|
|
|
|
|
|
|
params[0], params[1]['bookmarkCount'], params[1]['illustTitle'], ','.join(params[1]['tags']), '', |
|
|
|
|
|
|
|
params[1]['imgUrl'])) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def zip(inputFile, outFile): |
|
|
|
def zip(inputFile, outFile): |
|
|
|
f = zipfile.ZipFile(outFile, 'w', zipfile.ZIP_DEFLATED) |
|
|
|
f = zipfile.ZipFile(outFile, 'w', zipfile.ZIP_DEFLATED) |
|
|
@ -79,7 +82,10 @@ def zip(inputFile,outFile): |
|
|
|
f.write(os.path.join(dirpath, filename), filename) |
|
|
|
f.write(os.path.join(dirpath, filename), filename) |
|
|
|
f.close() |
|
|
|
f.close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fsize = '' |
|
|
|
fsize = '' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_nodes(param): |
|
|
|
def get_nodes(param): |
|
|
|
global nodes, fsize, imgPath |
|
|
|
global nodes, fsize, imgPath |
|
|
|
nodes = [] |
|
|
|
nodes = [] |
|
|
@ -122,7 +128,6 @@ def get_nodes(param): |
|
|
|
return [nodes, tip, fsize] |
|
|
|
return [nodes, tip, fsize] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
if __name__ == "__main__": |
|
|
|
if (len(sys.argv)) == 5 and sys.argv[2].isdigit() and sys.argv[3].isdigit(): |
|
|
|
if (len(sys.argv)) == 5 and sys.argv[2].isdigit() and sys.argv[3].isdigit(): |
|
|
|
try: |
|
|
|
try: |
|
|
|