百度文庫Word下載器


最近我媽的文庫VIP用完了,但還有很多資源要下載,於是我便在網上找下載工具。

總算找到個完美的!(雖然沒界面)

既然沒界面,那就自己寫一個唄!

原作者

該程序的下載和寫入部分由地球守衛者制作

原文鏈接

下載

GitHub

https://github.com/TotoWang-hhh/du_doc_down.git

上代碼

 

?
import requests
import json
import re
import docx
import tkinter as tk
import easygui
import webbrowser
 
def web_ui():
    webbrowser.open("https://totowang-hhh.github.io")
 
def web_main():
    webbrowser.open("https://www.cnblogs.com/huangguifeng/")
 
def start():
    get_document(urlEnter.get())
 
#界面
window=tk.Tk()
window.geometry('800x450')
window.title('Du Doc Down 文庫下載器')
window.iconbitmap(".\\icon.ico")
 
webBtn_ui=tk.Button(window,text='界面 By 人工智障',width=25,height=2,font=('仿宋','12'),fg='white',bg='blue',command=web_ui)
webBtn_ui.place(x=10,y=10)
 
webBtn_main=tk.Button(window,text='下載程序 By 地球守衛者',width=25,height=2,font=('仿宋','12'),fg='black',bg='yellow',command=web_main)
webBtn_main.place(x=250,y=10)
 
urlEnterTip=tk.Label(window,text='請將文檔鏈接粘貼到此處')
urlEnterTip.place(x=10,y=105)
urlEnter=tk.Entry(window,bd=2,show=None,width=66)
urlEnter.place(x=10,y=130)
 
downBtn=tk.Button(window,text='下載',font=('等線','15'),fg='white',bg='green',width=43,height=2,command=start)
downBtn.place(x=10,y=160)
 
tipsTitle=tk.Label(window,text='注意',font=('等線','20'))
tipsTitle.place(x=550,y=50)
tipsA=tk.Label(text='·暫時僅支持下載Word文檔',font=('等線','13'),anchor='w')
tipsA.place(x=550,y=100)
tipsB=tk.Label(text='·暫不支持下載文字格式與附件',font=('等線','13'),anchor='w')
tipsB.place(x=550,y=120)
 
def get_document(url):
    # 文庫url
    sess = requests.Session()
    html = sess.get(url).content.decode("gbk")
    # 抓取到文檔標題
    title = re.search('id="doc-tittle-0">(.*?)</span>', html).group(1)
    # 使用正則提取 文檔內容的url
    res = re.search("WkInfo.htmlUrls = '(.*)'", html).group(1)
    # \\x22是linux中的引號,替換成Python中的引號
    res = res.replace("\\x22", "\"")
    # 轉成字典
    data = json.loads(res)
    # 新建一個文檔
    document = docx.Document()
    string = ""
    for i in data["json"]:
        url = i["pageLoadUrl"]  # 獲取到url
        url = url.replace("\\", "")  # url中有轉義符\去掉
        # 請求文檔內容
        data = requests.get(url).content.decode("utf-8")
        # 提取文本數據
        res = re.search("wenku_\d*\((.*)\)", data, re.S).group(1)
        # 將json對象數據轉成Python對象
        data = json.loads(res)
        for i in data['body']:
            # 判斷數據是什么類型
            if i["t"] == "word":
                # 獲取到文本
                string += str(i["c"])
                # ps中不為空並且_enter==1的時候是換行也就是一段內容
                if i["ps"] and i["ps"].get("_enter") == 1:
                    document.add_paragraph(string)  # 將一段內容寫入到word
                    string = ""  # 重新復制 "" 表示新的一段文本
    # 保存word
    document.save(easygui.filesavebox(title='保存文件',default=title+".docx"))

下載

抱歉,下載鏈接來晚了,最終沒有選擇誠通網盤,因為發現存儲時間有限。請到我的Github下載,鏈接
若無法點擊超鏈接,請復制以下網址到瀏覽器地址欄https://github.com/TotoWang-hhh/du_doc_down.git


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM