python 制作網(wǎng)站小說下載器
基本開發(fā)環(huán)境
· Python 3.6
· Pycharm
相關(guān)模塊使用

目標(biāo)網(wǎng)頁分析

輸入想看的小說內(nèi)容,點(diǎn)擊搜索

這里會返回很多結(jié)果,我只選擇第一個(gè)
網(wǎng)頁數(shù)據(jù)是靜態(tài)數(shù)據(jù),但是要搜索,是post請求,需要提價(jià)data參數(shù),如下圖所示:

然后通過解析網(wǎng)站數(shù)據(jù),獲取第一個(gè)小說i的詳情頁url即可
靜態(tài)網(wǎng)頁的獲取,難度是不大的。
def search():
search_url = 'http://www.xbiquge.la/modules/article/waps.php'
data = {
'searchkey': name
}
response = requests.post(url=search_url, data=data, headers=headers)
selector = get_parsing(response.text)
novel_url = selector.css('.even a::attr(href)').extract_first()
1、獲取每本小說的章節(jié)名以及url地址
所有的章節(jié)名以及url地址,都包含在dd標(biāo)簽里面

2、獲取url后,需要拼接
'/23/23019/11409705.html' # 這是網(wǎng)頁獲取到的url 'http://www.xbiquge.la/23/23019/11409705.html' # 這是真實(shí)的小說章節(jié)內(nèi)容url地址
3、小說名字,直接獲取即可。
def download_one_book(index_url):
response = get_response(index_url)
response.encoding = response.apparent_encoding
sel = get_parsing(response.text)
book_name = sel.css('#info h1::text').get()
# 提取了所有章節(jié)的下載地址
urls = sel.css('#list dd a::attr(href)').getall()
# 不要最新的 12 章放在最前main
for url in urls:
chapter_url = 'http://www.xbiquge.la' + url
print(chapter_url)
保存下載每章小說內(nèi)容
def download_one_chapter(chapter_url, book_name):
response = get_response(chapter_url)
response.encoding = response.apparent_encoding
html = response.text
selector = get_parsing(html)
h1 = selector.css('.bookname h1::text').get()
content = selector.css('#content::text').getall()
lines = []
for c in content:
lines.append(c.strip())
print(h1)
text = '\n'.join(lines)
file = open(book_name + '.txt', mode='a', encoding='utf-8')
file.write(h1)
file.write('\n')
file.write(text)
file.write('\n')
file.close()
小說軟件界面
root = Tk()
root.title('小說下載器')
root.geometry('560x450+400+200')
label = Label(root, text='請輸入下載小說名字:', font=('華文行楷', 20))
label.grid()
entry = Entry(root, font=('隸書', 20))
entry.grid(row=0, column=1)
text = Listbox(root, font=('隸書', 16), width=50, heigh=15)
text.grid(row=2, columnspan=2)
button1 = Button(root, text='開始下載', font=('隸書', 15), command=search)
button1.grid(row=3, column=0)
button2 = Button(root, text='退出程序', font=('隸書', 15), command=root.quit)
button2.grid(row=3, column=1)
root.mainloop()
顯示下載內(nèi)容
def novel_load(title):
text.insert(END, '正在保存:{}'.format(title))
# 文本框滾動(dòng)
text.see(END)
# 更新
text.update()
實(shí)現(xiàn)效果

以上就是python 制作網(wǎng)站小說下載器的詳細(xì)內(nèi)容,更多關(guān)于python 小說下載器的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
python shell命令行中import多層目錄下的模塊操作
這篇文章主要介紹了python shell命令行中import多層目錄下的模塊操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03
Pandas如何將Timestamp轉(zhuǎn)為datetime類型
這篇文章主要介紹了Pandas如何將Timestamp轉(zhuǎn)為datetime類型,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07
使用Python分析文本數(shù)據(jù)的詞頻并詞云圖可視化
這篇文章主要給大家介紹了關(guān)于如何使用Python分析文本數(shù)據(jù)的詞頻并詞云圖可視化,文章中有詳細(xì)的圖文介紹和代碼示例,對我們的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2023-09-09
備戰(zhàn)618!用Python腳本幫你實(shí)現(xiàn)淘寶秒殺
本次的文章,分享一個(gè)淘寶秒殺腳本,這個(gè)腳本用Python編寫,使用了Python庫selenium,并且通過selenium + chromedriver,用程序控制chrome瀏覽器,完成搶購的一系列操作.有了這個(gè)腳本,大家至少可以與其他的機(jī)器人站在同一起跑線上,公平搶購喜歡的寶貝 ,需要的朋友可以參考下2021-06-06
Python利用pynput實(shí)現(xiàn)劃詞復(fù)制功能
這篇文章主要為大家想詳細(xì)介紹了Python如何利用pynput實(shí)現(xiàn)劃詞復(fù)制功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-05-05
Python-OpenCV深度學(xué)習(xí)入門示例詳解
深度學(xué)習(xí)已經(jīng)成為機(jī)器學(xué)習(xí)中最受歡迎和發(fā)展最快的領(lǐng)域。深度學(xué)習(xí)的常見應(yīng)用包括語音識別、圖像識別、自然語言處理、推薦系統(tǒng)等等。本文將通過一些示例代碼,帶你詳細(xì)了解深入學(xué)習(xí)2021-12-12

