设为首页收藏本站

简体中文 繁體中文 English 日本語 Deutsch 한국 사람 بالعربية TÜRKÇE português คนไทย Français

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 51|回复: 6

写了个漫画下载的脚本

[复制链接]

50

主题

410

回帖

1060

积分

金牌会员

积分
1060
发表于 2020-4-15 14:54:43 | 显示全部楼层 |阅读模式
本帖最后由 oldj 于 2020-4-16 12:52 编辑

接https://www.52.ht/thread-674260-1-1.html
因为看老哥一直没发出来,所以就写了一个脚本下载
支持多线程下载
注意使用前修改json_url为json地址
脚本下载地址
https://github.com/tusik/json-parser-downloader/blob/master/process.py
https://raw.githubusercontent.com/tusik/json-parser-downloader/master/process.py
如果出现创建目录的编码报错,请注意设置环境编码为utf8





已修复目录错误,现在的话可能部分内容会重新下载而且目录结构有点不一样


[ol]
  • # -*- coding: UTF-8 -*-
  • import psycopg2
  • import requests
  • import sys,json,os,re
  • from threading import Thread
  • def download_img(path,url):
  •     r = requests.get(url, headers=headers)
  •     filename_t = str(url).split('/')
  •     filename = filename_t[len(filename_t)-1]
  •     filename = re.sub('[\/:*?"|]','_',filename)
  •     with open(path+'/'+filename, 'wb') as f:
  •         f.write(r.content)
  • headers = {
  •     'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) '
  •                   'Chrome/80.0.3987.149 Safari/537.36 '
  • }
  • title = ''
  • json_url = ''
  • if not os.path.exists("export.json"):
  •     r = requests.get(json_url, stream=True)
  •     f = open("export.json", "wb")
  •     for chunk in r.iter_content(chunk_size=512):
  •         if chunk:
  •             f.write(chunk)
  • with open("export.json","r",encoding='utf-8') as data:
  •     json_obj = json.load(data)
  • for i in json_obj:
  •     title = i['title']
  •     title = re.sub('[\/:*?"|]','_',title)
  •     if not os.path.exists(title):
  •         os.mkdir(title)
  •     r = requests.get(i['cover'], headers=headers)
  •     with open(i['title']+"/cover.jpg", 'wb') as f:
  •         f.write(r.content)
  •     chaper = ''
  •     for k in i['chapters']:
  •         threads = []
  •         cp_title = k['title']
  •         cp_title = re.sub('[\/:*?"|]','_',cp_title)
  •         if os.path.exists(title+'/'+k['title']):
  •             cp_title = k['title']
  •         if not os.path.exists(title+'/'+cp_title):
  •             os.mkdir(title+'/'+cp_title)
  •         print('Downloading ' + cp_title)
  •         for j in k['images']:
  •             filename_t = str(j).split('/')
  •             filename = filename_t[len(filename_t)-1]
  •             if os.path.exists(title+'/'+cp_title+'/'+filename):
  •                 continue
  •             t = Thread(target=download_img,args=[title+'/'+cp_title,j])
  •             t.start()
  •             threads.append(t)
  •         for t in threads:
  •             t.join()
  • [/ol]复制代码
  • 回复

    使用道具 举报

    10

    主题

    1463

    回帖

    3000

    积分

    论坛元老

    积分
    3000
    发表于 2020-4-15 14:56:36 | 显示全部楼层
    感谢分享   
    回复

    使用道具 举报

    112

    主题

    565

    回帖

    1602

    积分

    金牌会员

    积分
    1602
    发表于 2020-4-15 15:10:00 | 显示全部楼层
    谢谢!
    回复

    使用道具 举报

    17

    主题

    253

    回帖

    629

    积分

    高级会员

    积分
    629
    发表于 2020-4-15 15:12:40 | 显示全部楼层
    感谢分享
    回复

    使用道具 举报

    27

    主题

    454

    回帖

    1085

    积分

    金牌会员

    积分
    1085
    发表于 2020-4-15 21:00:19 | 显示全部楼层
    爬到哪吒传出错了QQ
    Downloading 哪吒传 公告
    Downloading 哪吒传 第33话(1)
    Downloading 哪吒传 第32话(4)
    Downloading 哪吒传 第32话(3)
    Downloading 哪吒传 第32话(2)
    Downloading 哪吒传 双12活动专题宣传~
    Downloading 哪吒传 第32话(1)
    Traceback (most recent call last):
      File "process.py", line 44, in
        os.mkdir(title+'/'+cp_title)
    FileNotFoundError: [Errno 2] No such file or directory: '哪吒传/哪吒传 单行本3-4册上市啦~(≧▽≦)/~'
    回复

    使用道具 举报

    50

    主题

    410

    回帖

    1060

    积分

    金牌会员

    积分
    1060
     楼主| 发表于 2020-4-16 08:24:34 | 显示全部楼层

    鼎剑阁 发表于 2020-4-15 21:00

    爬到哪吒传出错了QQ
    Downloading 哪吒传 公告
    Downloading 哪吒传 第33话(1)



    emm没想到还有这种标题,等我处理一下
    回复

    使用道具 举报

    27

    主题

    454

    回帖

    1085

    积分

    金牌会员

    积分
    1085
    发表于 2020-4-15 21:00:00 | 显示全部楼层
    打包那个不是这个呀,那个是叮咚的,这个是节操的
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|Discuz! X

    GMT+8, 2026-2-7 13:36 , Processed in 0.015497 second(s), 4 queries , Gzip On, Redis On.

    Powered by Discuz! X3.5

    © 2001-2025 Discuz! Team.

    快速回复 返回顶部 返回列表