獲取免費小說,免費小說隨時看
很多時候我們追小說時候,總會有很多的廣告,讓我們看小說的心情大打折扣,下面讓我們來獲取免費小說,獲取到本地隨時可以看吧。

import requests,re,parsel
from fake_useragent import UserAgent
ua = UserAgent()
header = {"User-Agent":ua.random}
Url = "https://www.167k.com/book/20761"
session = requests.session()
session.headers = header
def local(url,title,num):
? ? try:
? ? ? ? res = session.get(url)
? ? ? ? if res.status_code == 200:
? ? ? ? ? ? url = "https://www.167k.com/phone/book/get_bookcontent?book_id={}&chapter_id={}".format(num[2], num[3])
? ? ? ? ? ? res = session.get(url)
? ? ? ? ? ? print(res.text)
? ? except Exception as e:
? ? ? ? print("詳細頁面請求出錯:",e)
def main():
? ? try:
? ? ? ? res = requests.get(Url,headers=header)
? ? ? ? # 獲取總標題 和一個圖片
? ? ? ? if res.status_code == 200:
? ? ? ? ? ? html = parsel.Selector(res.text)
? ? ? ? ? ? image = html.xpath('//div[@class="de_navtu"]/div[1]/img/@src').extract_first()
? ? ? ? ? ? # 留意一下這里標題是否有作者名字
? ? ? ? ? ? title_all = html.xpath('//div[@class="de_navtu"]/div[2]/div[1]/text()').extract_first()
? ? ? ? ? ? name = html.xpath('//div[@class="de_navtu"]/div[2]/div[1]/span/text()').extract_first()
? ? ? ? ? ? title_all = title_all.replace("\n","").replace("\t","")
? ? ? ? ? ? mold = html.xpath('//div[@class="de_navtu"]/div[2]/div[2]/div/text()').extract()
? ? ? ? ? ? # print(mold)
? ? ? ? ? ? # print("圖片鏈接:",image)
? ? ? ? ? ? # print("總標題:",title_all)
? ? ? ? ? ? # print("作者:",name,len(name))
? ? ? ? ? ? # print(title_all,len(title_all))
? ? ? ? ? ? titles = html.xpath('//div[@class="bo_zj"]/ul/li/a/@title').extract()
? ? ? ? ? ? urls = html.xpath('//div[@class="bo_zj"]/ul/li/a/@href').extract()
? ? ? ? ? ? for title,url in zip(titles,urls):
? ? ? ? ? ? ? ? #? https://www.167k.com/book/20761/126590035? ? ?構(gòu)造這個URL
? ? ? ? ? ? ? ? #? https://www.167k.com/phone/book/get_bookcontent?book_id=20761&chapter_id=126590035
? ? ? ? ? ? ? ? #? https://www.167k.com/phone/book/get_bookcontent?book_id=20761&chapter_id=126590117
? ? ? ? ? ? ? ? if url == '/book/20761/126590007':
? ? ? ? ? ? ? ? ? ? num = url.split('/')
? ? ? ? ? ? ? ? ? ? url = "https://www.167k.com{}".format(url)
? ? ? ? ? ? ? ? ? ? local(url,title,num)
? ? ? ? ? ? ? ? ? ? print(url)
? ? ? ? ? ? ? ? # url = "https://www.167k.com{}".format(url)
? ? ? ? ? ? ? ? # print(title,url)
? ? ? ? else:
? ? ? ? ? ? print("不是200")
? ? except Exception as e:
? ? ? ? print("請求主頁面出錯:",e)
if __name__ == '__main__':
? ? main()