[Python] 纯文本查看 复制代码
import json
import re
import time
import os
import sys
import requests
class Main():
bookname = input('请输入书名:')
url_dict = {
'八一中文网1':['https://www.zwdu.com/','https://www.zwdu.com/search.php?keyword=','utf-8','GET','<div class="result-game-item-detail">(.*?)<div class="search-result-page">'],
'八一中文网2':['http://www.81zw.in/','http://www.81zw.in/plus/search.php?kwtype=0&searchtype=&q=','gbk','GET','<ul class="ul_b_list">(.*?)</ul>'],
'八一中文网3':['https://www.81xs.cc/','https://www.81xs.cc/s.php?ie=gbk&q=','gbk','GET'],
'八一中文网4':['https://www.81zw.com.tw/','https://www.81zw.com.tw/modules/article/search.php?searchkey=','gbk','GET'],
'笔趣读1':['http://www.biqudu.tv/','http://www.biqudu.tv/s.php?q=','utf-8','GET'],
'笔趣读2':['https://www.biqugetv.com/','https://www.biqugetv.com/search.php?keyword=','utf-8','GET'],
'笔趣读3':['http://www.biquduge.com/','http://www.biquduge.com/modules/article/search.php','gbk','POST',{'searchkey':str(bookname.encode('gbk'))[:-1][2:].replace('\\x','%'),'searchtype': 'articlename'}],#text = str('书名'.encode('gbk'))[:-1][2:].replace('\\x','%')
'笔趣读4':['https://m.biqu55.com/','https://m.biqu55.com/home/search','utf-8','POST',{'action': 'search','q':bookname}],
'中文阅读网':['https://www.zwydw.com/','https://www.zwydw.com/s.php?ie=gbk&q=','gbk','GET'],
}
def choose_from(self):
from_list = []
for x,i in enumerate(self.url_dict):
print(x+1,i)
from_list.append(i)
choose = input('请输入您想要的书源序号(目前仅支持书源1):')
#print(len(self.url_dict))#这句话输出书源数量
if choose == 'q':
sys.exit()
elif int(choose)>len(self.url_dict) or int(choose)<1:
os.system('cls')
print('请重新输入!(目前仅支持书源1 退出请按q)\n')
self.choose_from()
return from_list[int(choose)-1]
def get_base_url(self,storename):
info_list = self.url_dict[storename]
#print(info_list)
method = info_list[3]
#print(method)
if method == 'POST':
res = requests.post(info_list[1],data=info_list[5])
#print(res.text)
search_txt = info_list[5]
if method == 'GET':
res = requests.get(info_list[1]+str(self.bookname.encode(info_list[2]))[:-1][2:].replace('\\x','%'))
#print(res.text)
search_txt = info_list[4]
return res.text,search_txt
def get_book_list(self,html,params):
def findall(tx1,tx2,tx3):
return re.findall(re.compile('{}(.*?){}'.format(tx1,tx2),re.S),tx3)
htm = re.findall(re.compile(params,re.S),html)
html = []
for i in htm:
bookname = findall(' title="','" c',i)[0]
url = findall('<a cpos="title" href="','" title=',i)[0]
describe = findall('<p class="result-game-item-desc">','</p>',i)[0]
auther = findall('<span>','</span>',findall('<p class="result-game-item-info-tag">','</p>',i)[0])[0].strip()
#print(url,bookname,auther,describe)
html.append((bookname,url,auther,describe))
#print(i.strip())
print(html)
a = Main()
#print(a.choose_from())
b = a.get_base_url(a.choose_from())
c = a.get_book_list(b[0],b[1])
#print(b)