2022-01-08 11:23:31 +00:00
|
|
|
|
import traceback
|
2022-07-31 08:27:58 +00:00
|
|
|
|
|
2022-07-26 09:54:43 +00:00
|
|
|
|
from bs4 import BeautifulSoup
|
2022-01-03 09:13:42 +00:00
|
|
|
|
|
2022-07-31 08:27:58 +00:00
|
|
|
|
from config import Config
|
2023-02-05 14:33:33 +00:00
|
|
|
|
from core.builtins import Url
|
2022-08-04 07:52:42 +00:00
|
|
|
|
from core.logger import Logger
|
2023-02-05 14:33:33 +00:00
|
|
|
|
from core.utils.http import get_url
|
2022-01-03 09:13:42 +00:00
|
|
|
|
|
2022-01-20 12:13:03 +00:00
|
|
|
|
|
2022-01-03 09:13:42 +00:00
|
|
|
|
async def jiki(term: str):
|
|
|
|
|
'''查询小鸡百科。
|
|
|
|
|
|
|
|
|
|
:param term: 需要查询的term。
|
|
|
|
|
:returns: 查询结果。'''
|
|
|
|
|
try:
|
2022-07-26 09:54:43 +00:00
|
|
|
|
api = 'https://jikipedia.com/search?phrase=' + term
|
|
|
|
|
webrender = Config('web_render')
|
|
|
|
|
if webrender:
|
|
|
|
|
api = webrender + 'source?url=' + api
|
2022-08-01 15:33:35 +00:00
|
|
|
|
html = await get_url(api, 200)
|
2022-08-04 07:52:42 +00:00
|
|
|
|
Logger.debug(html)
|
2022-07-26 09:54:43 +00:00
|
|
|
|
bs = BeautifulSoup(html, 'html.parser')
|
|
|
|
|
result = bs.select_one('[data-index="0"]')
|
|
|
|
|
title_ele = result.select_one(
|
|
|
|
|
'a.title-container.block.title-normal')
|
|
|
|
|
content_ele = result.select_one('.lite-card-content')
|
|
|
|
|
|
|
|
|
|
title = title_ele.get_text()
|
|
|
|
|
link = title_ele.get('href')
|
|
|
|
|
content = content_ele.get_text()
|
|
|
|
|
|
|
|
|
|
results = bs.select('.lite-card').__len__()
|
|
|
|
|
count = str(result) if results < 15 else '15+'
|
2022-01-17 13:28:49 +00:00
|
|
|
|
return f'[小鸡百科]({count}个结果):{title}\n{content}\n{str(Url(link))}'
|
2022-01-08 11:23:31 +00:00
|
|
|
|
except Exception:
|
|
|
|
|
traceback.print_exc()
|
2022-01-03 09:13:42 +00:00
|
|
|
|
return '[小鸡百科] 查询出错。'
|