前语

本文的文字及圖片來源於網絡,僅供學習、沟通运用,不具有任何商業用处,如有問題請及時聯系我們以作處理。

配資10倍杠桿,配資10倍杠桿

PS:如有需求Python學習資料的小夥伴能够加點擊下方鏈接自行獲取

msci169隻股票名單,msci169隻股票名單

python免費學習資料以及群沟通回答點擊即可参加

118001,118001

開發东西

Python版别:3.6.5

相關模塊:requests模塊parsel模塊爬取網站https://www.tianyabook.com/shu/3801.html

獲取每一章小說鏈接

import requestsimport parselurl = 'https://www.tianyabook.com/shu/3801.html'headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'}response = requests.get(url=url, headers=headers)selector = parsel.Selector(response.text)page_urls = selector.css('.panel-body dd a::attr(href)').getall()

獲取每一章小說內容以及章節姓名

new_url = 'https://www.tianyabook.com' + page_urlresponse = requests.get(url=new_url, headers=headers)response.encoding = response.apparent_encodingselector = parsel.Selector(response.text)content = selector.css('#htmlContent::text').getall()title = selector.css('.page-header h1::text').get()html_data = ''.join(content)html_content = html_data.strip()print(html_content )

小說內容保存本地txt

with open('金瓶梅.txt', mode='a', encoding='utf-8') as f: f.write(title) f.write('\n') f.write(html_content) f.write('\n') print('{}已下載完结'.format(title))