mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-Nonebot.git
synced 2026-04-01 22:04:51 +00:00
fix(light_novel):新增获取信息失败时异常抛出
This commit is contained in:
parent
2c1966340b
commit
fbe9e69922
2 changed files with 21 additions and 12 deletions
|
|
@ -4,8 +4,6 @@ import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from src.configs.api_config import wenku8_username, wenku8_password, proxy_api
|
from src.configs.api_config import wenku8_username, wenku8_password, proxy_api
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 登录页面的URL
|
# 登录页面的URL
|
||||||
login_url = 'https://www.wenku8.net/login.php?jumpurl=http%3A%2F%2Fwww.wenku8.net%2Findex.php'
|
login_url = 'https://www.wenku8.net/login.php?jumpurl=http%3A%2F%2Fwww.wenku8.net%2Findex.php'
|
||||||
index_url = 'https://www.wenku8.net/index.php'
|
index_url = 'https://www.wenku8.net/index.php'
|
||||||
|
|
@ -24,20 +22,22 @@ login_data = {
|
||||||
'action': 'login'
|
'action': 'login'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_proxy(headers):
|
def get_proxy(headers):
|
||||||
#proxy_url可通过多米HTTP代理网站购买后生成代理api链接,每次请求api链接都是新的ip
|
# proxy_url可通过多米HTTP代理网站购买后生成代理api链接,每次请求api链接都是新的ip
|
||||||
proxy_url = proxy_api
|
proxy_url = proxy_api
|
||||||
aaa=requests.get(proxy_url, headers=headers).text
|
aaa = requests.get(proxy_url, headers=headers).text
|
||||||
proxy_host = aaa.splitlines()[0]
|
proxy_host = aaa.splitlines()[0]
|
||||||
print('代理IP为:'+proxy_host)
|
print('代理IP为:' + proxy_host)
|
||||||
#proxy_host='117.35.254.105:22001'
|
# proxy_host='117.35.254.105:22001'
|
||||||
#proxy_host='192.168.0.134:1080'
|
# proxy_host='192.168.0.134:1080'
|
||||||
proxy = {
|
proxy = {
|
||||||
'http': 'http://'+proxy_host,
|
'http': 'http://' + proxy_host,
|
||||||
'https': 'http://'+proxy_host
|
'https': 'http://' + proxy_host
|
||||||
}
|
}
|
||||||
return proxy
|
return proxy
|
||||||
|
|
||||||
|
|
||||||
async def login():
|
async def login():
|
||||||
# 发送登录请求
|
# 发送登录请求
|
||||||
with requests.Session() as session:
|
with requests.Session() as session:
|
||||||
|
|
@ -99,7 +99,8 @@ async def get_books():
|
||||||
# print(orders[7].text)
|
# print(orders[7].text)
|
||||||
with open(getcwd() + "/src/clover_lightnovel/output1.html", 'w', encoding='utf-8') as file:
|
with open(getcwd() + "/src/clover_lightnovel/output1.html", 'w', encoding='utf-8') as file:
|
||||||
file.write(head + str(orders[7]).replace('(<a href="https://www.wenku8.net/zt/sugoi/2025.php"', '').replace(
|
file.write(head + str(orders[7]).replace('(<a href="https://www.wenku8.net/zt/sugoi/2025.php"', '').replace(
|
||||||
'target="_blank">查看 这本轻小说真厉害!2025 TOP榜单</a>)', '') + str(orders[8]) + str(orders[9]) + str(orders[10]))
|
'target="_blank">查看 这本轻小说真厉害!2025 TOP榜单</a>)', '') + str(orders[8]) + str(orders[9]) + str(
|
||||||
|
orders[10]))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
from datetime import datetime
|
from datetime import datetime, time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import requests.exceptions
|
||||||
from nonebot.rule import to_me
|
from nonebot.rule import to_me
|
||||||
from nonebot.plugin import on_command
|
from nonebot.plugin import on_command
|
||||||
from nonebot.adapters.qq import MessageSegment
|
from nonebot.adapters.qq import MessageSegment
|
||||||
|
|
@ -15,6 +17,12 @@ async def get_ln():
|
||||||
file = Path() / light_novel_path / f"{now.date()}.png"
|
file = Path() / light_novel_path / f"{now.date()}.png"
|
||||||
if not os.path.exists(file):
|
if not os.path.exists(file):
|
||||||
await light_novel.send("正在为您整理最新轻小说咨询哦,请稍等🥳")
|
await light_novel.send("正在为您整理最新轻小说咨询哦,请稍等🥳")
|
||||||
|
try:
|
||||||
await get_ln_image()
|
await get_ln_image()
|
||||||
|
except requests.exceptions.InvalidURL as e:
|
||||||
|
print("\033[32m" + str(time.strftime("%m-%d %H:%M:%S")) +
|
||||||
|
"\033[0m [" + "\033[31;1mFAILED\033[0m" + "]" +
|
||||||
|
"\033[31;1m requests.exceptions.InvalidURL \033[0m" + str(e))
|
||||||
|
await light_novel.finish("获取信息失败了,请重试。")
|
||||||
now = datetime.now().date()
|
now = datetime.now().date()
|
||||||
await light_novel.finish(MessageSegment.file_image(Path(light_novel_path+f"{now}.png")))
|
await light_novel.finish(MessageSegment.file_image(Path(light_novel_path+f"{now}.png")))
|
||||||
Loading…
Reference in a new issue