1 Star 5 Fork 2

weder/doc_downloader_web

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
douding.py 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
豆腐 提交于 2020-02-10 17:09 +08:00 . init commit
from bs4 import BeautifulSoup
import requests
from tqdm import trange
import urllib
import shutil
import os
from img2pdf import conpdf
import requests
def download(url, callback):
try:
text = requests.get(url).text
pos = text.index('allPage:')
pages = int(text[pos + 8: pos + 12].split(',')[0])
id = url.split('.')[-2].split('-')[-1]
html = BeautifulSoup(text, features='lxml')
title = html.title.string.replace('/', '.')
print(f'豆丁:《{title}》')
if os.path.exists(f'./output/{title}.pdf'):
return True, title
if os.path.exists(f'./temp/{title}'):
shutil.rmtree(f'./temp/{title}')
os.makedirs(f'./temp/{title}')
for i in trange(pages):
url = f"http://211.147.220.164/index.jsp?file={id}&width=1600&pageno={i + 1}"
res = requests.get(url)
with open(f'./temp/{title}/{i+1}.jpg', 'wb') as f:
f.write(res.content)
callback(i, pages, "正在下载:%s" % title)
print('下载完毕,正在转码')
callback(99, 100, "正在转码")
conpdf(f'output/{title}.pdf', f'./temp/{title}', '.jpg', True)
return True, title
except Exception as e:
return False, e
if __name__ == "__main__":
download("https://jz.docin.com/p-1995868152.html")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/changeWeder/doc_downloader_web.git
git@gitee.com:changeWeder/doc_downloader_web.git
changeWeder
doc_downloader_web
doc_downloader_web
master

搜索帮助