Skip to content

Commit 0d4ee96

Browse files
committed
fix: error when get forwarded notices in myZJU
1 parent 75af101 commit 0d4ee96

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

zjuintl_assistant/assistant.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,21 @@ def get_myZJU_notices(self, count: int, EN: bool = False, get_content: bool = Fa
443443
title = notice.a.text
444444
if "[Top]" in notice.text:
445445
title = "[Top] " + title
446-
link = f"https://www.intl.zju.edu.cn{notice.a['href']}"
446+
link = notice.a["href"]
447+
if not link.startswith("http"):
448+
link = f"https://www.intl.zju.edu.cn{link}"
447449

448450
content = ""
449451
if get_content:
450-
content_resp = session.get(link)
451-
content_soup = bs4.BeautifulSoup(content_resp.text, "html.parser")
452-
content = content_soup.find("div", class_="row row-offcanvas row-offcanvas-left clearfix").prettify()
452+
if not notice.a["href"].startswith("http"):
453+
content_resp = session.get(link)
454+
content_soup = bs4.BeautifulSoup(content_resp.text, "html.parser")
455+
content = content_soup.find("div", class_="row row-offcanvas row-offcanvas-left clearfix").prettify()
456+
else:
457+
if EN:
458+
content = "This is an external link, no content preview available"
459+
else:
460+
content = "这是一个外部链接,没有内容预览"
453461

454462
date = datetime.datetime.strptime(item.find_all("div")[-1].text, "%Y-%m-%d")
455463

0 commit comments

Comments
 (0)