🐛 修复一个小错误

This commit is contained in:
xtaodada 2022-10-03 17:35:32 +08:00
parent 2bda99e05f
commit 288501dbc5
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
2 changed files with 25 additions and 12 deletions

View File

@ -90,11 +90,17 @@ async def get_loft(url: str) -> List[LofterItem]:
def parse_loft_user(url: str, content: str):
username = urlparse(url).hostname.split(".")[0]
soup = BeautifulSoup(content, "lxml")
user = soup.find("div", {"class": "selfinfo"})
avatar = user.find("img").get("src").split("?")[0]
name = user.find("h1").getText()
bio = user.find("div", {"class": "text"}).getText()
return username, avatar, name, bio, soup
if user := soup.find("div", {"class": "selfinfo"}):
avatar = user.find("img").get("src").split("?")[0]
name = user.find("h1").getText()
bio = user.find("div", {"class": "text"}).getText()
return username, avatar, name, bio, soup
if user := soup.find("div", {"class": "g-hdc box"}):
avatar = user.find("img").get("src").split("?")[0]
name = user.find("h1").getText()
bio = user.find("p", {"class": "cont"}).getText()
return username, avatar, name, bio, soup
return username, None, "未知用户", "", soup
async def get_loft_user(url: str):

View File

@ -30,13 +30,20 @@ async def lofter_share(_: Client, message: Message):
await message.reply_media_group(media=await input_media(img[:9], static), quote=True)
else:
text, avatar, username, status_link = await get_loft_user(url)
await message.reply_photo(
avatar,
caption=text,
quote=True,
reply_markup=lofter_user_link(username, status_link)
)
if avatar:
await message.reply_photo(
avatar,
caption=text,
quote=True,
reply_markup=lofter_user_link(username, status_link)
)
else:
await message.reply_text(
text,
quote=True,
disable_web_page_preview=True,
reply_markup=lofter_user_link(username, status_link)
)
except Exception as e:
print(e)
breakpoint()
raise ContinuePropagation