From dd147b0616cd9320bcb776c05383c785bc3dc200 Mon Sep 17 00:00:00 2001 From: Well404 Date: Mon, 8 Jul 2024 20:39:50 +0800 Subject: [PATCH] =?UTF-8?q?:bugs:=20=E4=BF=AE=E5=A4=8D=E4=B8=93=E6=A0=8F?= =?UTF-8?q?=E6=96=87=E5=AD=97=E5=86=85=E5=AE=B9=E8=A7=A3=E6=9E=90=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot_plugin_bilichat/content/column.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nonebot_plugin_bilichat/content/column.py b/nonebot_plugin_bilichat/content/column.py index 563a536..3932e9b 100644 --- a/nonebot_plugin_bilichat/content/column.py +++ b/nonebot_plugin_bilichat/content/column.py @@ -48,9 +48,13 @@ async def from_id(cls, bili_number: str, options: Options | None = None): cv = cv.text http_parser: _Element = etree.fromstring(cv, etree.HTMLParser(encoding="utf-8")) cv_title: str = http_parser.xpath('//h1[@class="title"]/text()')[0] - main_article: _Element = http_parser.xpath('//div[@id="read-article-holder"]')[0] - plist: _ElementUnicodeResult = main_article.xpath(XPATH) - cv_text = [text.strip() for text in plist if text.strip()] + try: + main_article: _Element = http_parser.xpath('//div[@id="read-article-holder"]')[0] + plist: _ElementUnicodeResult = main_article.xpath(XPATH) + cv_text = [text.strip() for text in plist if text.strip()] + except Exception: + logger.warning(f"专栏 cv{cvid} 文字内容解析失败,可能是专栏格式不受支持或未包含文字内容。") + cv_text = ["专栏文字内容解析失败,可能是专栏格式不受支持或未包含文字内容。"] b23_url = await get_b23_url(f"https://www.bilibili.com/read/cv{cvid}") except AbortError: raise