Skip to content

Commit 43ef45a

Browse files
committed
feat: replace relative links in notices of myZJU
1 parent 0d4ee96 commit 43ef45a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

zjuintl_assistant/assistant.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,16 @@ def get_myZJU_notices(self, count: int, EN: bool = False, get_content: bool = Fa
452452
if not notice.a["href"].startswith("http"):
453453
content_resp = session.get(link)
454454
content_soup = bs4.BeautifulSoup(content_resp.text, "html.parser")
455+
456+
# replace relative links
457+
for elem in content_soup.find_all(["a", "img"]):
458+
if "href" in elem.attrs:
459+
if not elem["href"].startswith("http"):
460+
elem["href"] = f"https://www.intl.zju.edu.cn{elem['href']}"
461+
if "src" in elem.attrs:
462+
if not elem["src"].startswith("http"):
463+
elem["src"] = f"https://www.intl.zju.edu.cn{elem['src']}"
464+
455465
content = content_soup.find("div", class_="row row-offcanvas row-offcanvas-left clearfix").prettify()
456466
else:
457467
if EN:

0 commit comments

Comments
 (0)