改成异步了, 改完彻底不能用了

This commit is contained in:
Twisuki 2024-12-11 01:50:06 +08:00
parent bb2f59eae9
commit ccb12f0f63
2 changed files with 81 additions and 76 deletions

View File

@ -7,4 +7,4 @@ async def meogirl():
# Search
async def search(msg : str, num : int = 3):
return str(mg_Search.search(msg, num))
return str(await mg_Search.search(msg, num))

View File

@ -1,15 +1,20 @@
from nonebot.log import logger
import re
import requests
import httpx
from bs4 import BeautifulSoup
def search(msg : str, num : int):
async def search(msg : str, num : int):
logger.info(f"搜索 : \"{msg}\"")
result = ""
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36'
}
url = "https://mzh.moegirl.org.cn/index.php?search=" + msg
response = requests.get(url)
async with httpx.AsyncClient() as client:
response = await client.get(url, headers = headers)
logger.info(response.headers.get('Location'))
logger.info(f"连接萌娘百科中, 状态码 : {response.status_code}")
"""