├── .README_images ├── 96ddb7e6.png ├── ddba56bc.png ├── efec2181.png └── img.png ├── .gitignore ├── LICENSE ├── README.md └── all_in_one.py /.README_images/96ddb7e6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dondaha/SJTU-BookDownloader/af69f02546780607ea97cd69a0ffc6d7ca3c66e8/.README_images/96ddb7e6.png -------------------------------------------------------------------------------- /.README_images/ddba56bc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dondaha/SJTU-BookDownloader/af69f02546780607ea97cd69a0ffc6d7ca3c66e8/.README_images/ddba56bc.png -------------------------------------------------------------------------------- /.README_images/efec2181.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dondaha/SJTU-BookDownloader/af69f02546780607ea97cd69a0ffc6d7ca3c66e8/.README_images/efec2181.png -------------------------------------------------------------------------------- /.README_images/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dondaha/SJTU-BookDownloader/af69f02546780607ea97cd69a0ffc6d7ca3c66e8/.README_images/img.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | dist/ 3 | saved/ 4 | .idea/ 5 | *.spec 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 dondaha 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SJTU-BookDownloader 2 | 用于快速便捷下载图书馆资源 3 | 4 | - [x] 下载图书的图片并合成PDF 5 | - [x] 使用教程 6 | - [ ] 多线程加速下载 7 | - [ ] 图形界面 8 | ## 使用教程 9 | 10 | ### 下载 11 | 建议在右侧直接下载`release`,不用在本地配置环境。点击`release`,选择`SJTU-BookDownloader-v1.0.exe`下载。 12 | 13 | ### 使用 14 | 首先你需要连接到校园网或者VPN,然后进入你要的图书的浏览界面, 15 | 这时在Microsoft Edge浏览器或者Google Chrome中按下F12, 16 | 并刷新页面,选中右侧网络一栏: 17 | 18 | ![](.README_images/img.png) 19 | 20 | 然后在左侧栏找到那个以 `http://jcft.lib.sjtu.edu.cn:83/png/png.dll?did=a175&pid=` 21 | 开头的一行 22 | 23 | ![](.README_images/efec2181.png) 24 | 25 | 26 | 右键那一行,点击复制/复制链接地址 27 | 28 | ![](.README_images/96ddb7e6.png) 29 | 30 | 之后打开 `SJTU-BookDownloader-v1.0.exe` ,直接右键点击窗口,粘贴刚才的链接 31 | 32 | ![](.README_images/ddba56bc.png) 33 | 34 | 回车即可,之后下载完毕会保存在程序相同目录的 `saved` 文件夹内。 35 | 36 | 问:为什么还要F12复制链接,如此麻烦 37 | 即答:通过这个链接,无需cookie就能下载 38 | -------------------------------------------------------------------------------- /all_in_one.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: UTF-8 -*- 3 | import requests 4 | from PIL import Image 5 | from io import BytesIO 6 | import time 7 | import datetime 8 | import os 9 | 10 | 11 | def download_source(url_url, headers, cookies): 12 | """下载文件,返回一个内存中的图片,如果下载失败则返回bool值False""" 13 | raw_picture = requests.get(url=url_url, stream=False, headers=headers, verify=False, cookies=cookies) 14 | raw_picture = raw_picture.content 15 | if len(raw_picture) != 0: 16 | raw_picture = BytesIO(raw_picture) 17 | try: 18 | raw_picture = Image.open(raw_picture).convert('RGB') 19 | except: 20 | print('网络错误') 21 | return False 22 | return raw_picture 23 | else: 24 | return False 25 | 26 | 27 | cold_time = 0.01 # 全局下载冷却时间 28 | url0 = input('输入封面地址:') 29 | 30 | # 计算下载过程耗时 31 | start_time = time.time() 32 | 33 | url0 = url0.split('&') 34 | # 准备链接头和链接尾 35 | url_head = str(url0[0]) + '&' + str(url0[1]) + '&jid=' 36 | url_tail = '.jpg&zoom=0' 37 | 38 | # 设置请求头以及cookie 39 | headers0 = {'Host': 'jcft.lib.sjtu.edu.cn:83', 'Connection': 'keep-alive', 40 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36 Edg/104.0.1293.63', 41 | 'Accept': 'image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8', 42 | 'Referer': 'http://jcft.lib.sjtu.edu.cn:9088/', 'Accept-Encoding': 'gzip, deflate', 43 | 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6'} 44 | cookies0 = {} # 没错,通过这种复制图片链接而不是预览页面链接的方式,我们不用cookie就能下载 45 | data = {} 46 | # 初始化图片列表 47 | images = list() 48 | 49 | # 首先下载封面cov,然后直接添加到图片列表images中 50 | print('开始下载封面') 51 | images.append(download_source(url_head + '/cov001' + url_tail, headers0, cookies0)) 52 | # 再下载封面bok,然后直接添加到图片列表images中 53 | images.append(download_source(url_head + '/bok001' + url_tail, headers0, cookies0)) 54 | # 再下载leg,然后直接添加到图片列表images中 55 | images.append(download_source(url_head + '/leg001' + url_tail, headers0, cookies0)) 56 | print('封面下载完成') 57 | 58 | # 使用一个while循环下载前言 59 | i = 1 60 | while True: 61 | url = url_head + "/fow" + f'{i:03d}' + url_tail 62 | img = download_source(url, headers0, cookies0) 63 | if isinstance(img, bool): 64 | print('前言下载完成') 65 | break 66 | else: 67 | images.append(img) 68 | print('前言下载中,完成第' + str(i) + '张前言的下载') 69 | i += 1 70 | time.sleep(cold_time) 71 | 72 | # 使用一个while循环下载目录 73 | i = 1 74 | while True: 75 | url = url_head + "/!" + f'{i:05d}' + url_tail 76 | img = download_source(url, headers0, cookies0) 77 | if isinstance(img, bool): 78 | print('目录下载完成') 79 | break 80 | else: 81 | images.append(img) 82 | print('目录下载中,完成第' + str(i) + '张目录的下载') 83 | i += 1 84 | time.sleep(cold_time) 85 | 86 | # 使用一个while循环下载正文 87 | i = 1 88 | while True: 89 | url = url_head + "/" + f'{i:06d}' + url_tail 90 | img = download_source(url, headers0, cookies0) 91 | if isinstance(img, bool): 92 | print('正文下载完成,开始将内存中的图片合成为PDF文档,保存在程序相同目录......') 93 | break 94 | else: 95 | images.append(img) 96 | print('正文下载中,完成第' + str(i) + '张正文的下载') 97 | i += 1 98 | time.sleep(cold_time) 99 | 100 | # 保存PDF 101 | img0 = images[0] 102 | now = datetime.datetime.now() 103 | if not os.path.exists('saved'): 104 | os.mkdir('saved') 105 | pdf_name = '.\\saved\\图书下载' + now.strftime("%Y_%m_%d_%H_%M_%S") + '.pdf' 106 | img0.save(pdf_name, "PDF", resolution=75.0, save_all=True, append_images=images[1:]) 107 | 108 | # 计算总过程耗时 109 | end_time = time.time() 110 | # 计算文件大小 111 | file_size = os.path.getsize(pdf_name)/float(1024)/float(1024) 112 | print('图书大小为:'+f'{file_size:.2f}'+'MB'+',下载此本图书过程共耗时:' + f'{end_time - start_time:.2f}'+'s') 113 | print('您要的文件已保存在:'+str(pdf_name)) 114 | input('按回车键退出...') 115 | --------------------------------------------------------------------------------