2021-11-23 21:44:59 +08:00
|
|
|
from utils.http_utils import AsyncHttpx
|
2021-11-04 16:11:50 +08:00
|
|
|
from configs.config import Config
|
2021-06-04 18:01:33 +08:00
|
|
|
from bs4 import BeautifulSoup
|
2021-05-20 19:21:05 +08:00
|
|
|
import platform
|
2021-07-30 21:21:51 +08:00
|
|
|
|
|
|
|
|
if platform.system() == "Windows":
|
2021-05-20 19:21:05 +08:00
|
|
|
import asyncio
|
2021-07-30 21:21:51 +08:00
|
|
|
|
2021-05-20 19:21:05 +08:00
|
|
|
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
|
|
|
|
|
|
|
|
|
|
2022-04-04 20:33:37 +08:00
|
|
|
url = "http://www.eclzz.mobi"
|
2021-05-20 19:21:05 +08:00
|
|
|
|
|
|
|
|
|
2022-02-19 18:20:19 +08:00
|
|
|
async def get_bt_info(keyword: str, page: int):
|
2021-11-23 21:44:59 +08:00
|
|
|
"""
|
|
|
|
|
获取资源信息
|
|
|
|
|
:param keyword: 关键词
|
|
|
|
|
:param page: 页数
|
|
|
|
|
"""
|
|
|
|
|
text = (await AsyncHttpx.get(f"{url}/s/{keyword}_rel_{page}.html", timeout=5)).text
|
|
|
|
|
if text.find("大约0条结果") != -1:
|
|
|
|
|
return
|
|
|
|
|
soup = BeautifulSoup(text, "lxml")
|
|
|
|
|
item_lst = soup.find_all("div", {"class": "search-item"})
|
|
|
|
|
bt_max_num = Config.get_config("bt", "BT_MAX_NUM")
|
|
|
|
|
bt_max_num = bt_max_num if bt_max_num < len(item_lst) else len(item_lst)
|
|
|
|
|
for item in item_lst[:bt_max_num]:
|
|
|
|
|
divs = item.find_all("div")
|
|
|
|
|
title = (
|
|
|
|
|
str(divs[0].find("a").text)
|
|
|
|
|
.replace("<em>", "")
|
|
|
|
|
.replace("</em>", "")
|
|
|
|
|
.strip()
|
|
|
|
|
)
|
|
|
|
|
spans = divs[2].find_all("span")
|
2022-02-19 18:20:19 +08:00
|
|
|
type_ = spans[0].text
|
2021-11-23 21:44:59 +08:00
|
|
|
create_time = spans[1].find("b").text
|
|
|
|
|
file_size = spans[2].find("b").text
|
|
|
|
|
link = await get_download_link(divs[0].find("a")["href"])
|
2022-02-19 18:20:19 +08:00
|
|
|
yield title, type_, create_time, file_size, link
|
2021-11-23 21:44:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
async def get_download_link(_url: str) -> str:
|
|
|
|
|
"""
|
|
|
|
|
获取资源下载地址
|
|
|
|
|
:param _url: 链接
|
|
|
|
|
"""
|
|
|
|
|
text = (await AsyncHttpx.get(f"{url}{_url}")).text
|
|
|
|
|
soup = BeautifulSoup(text, "lxml")
|
|
|
|
|
return soup.find("a", {"id": "down-url"})["href"]
|