Skip to content

Commit

Permalink
fix: article ([提问] 获取专栏有部分专栏似乎无法正常解析图片 #749)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo2011 committed May 12, 2024
1 parent 587d86b commit 6f8293c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions bilibili_api/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ async def parse(el: BeautifulSoup):
node_list.append(node)

node.children = await parse(e)
if e.text != "":
node_list += await parse(e)

elif "class" in e.attrs:
className = e.attrs["class"][0]
Expand All @@ -373,12 +375,7 @@ async def parse(el: BeautifulSoup):
node.children = await parse(e)
else:
if e.text != "":
# print(e.text.replace("\n", ""))
# print()
node = TextNode(e.text)
# print("Add a text node: ", e.text)
node_list.append(node)
node.children = parse(e) # type: ignore
node_list += (await parse(e))

elif e.name == "blockquote":
# 引用块
Expand Down Expand Up @@ -458,6 +455,19 @@ async def parse(el: BeautifulSoup):
node_list.append(node)

node.room_id = int(aid)

if "seamless" in className:
# 图片节点
node = ImageNode()
node_list.append(node)

node.url = "https:" + e.find("img").attrs["data-src"] # type: ignore

figcaption_el: BeautifulSoup = e.find("figcaption") # type: ignore

if figcaption_el:
if figcaption_el.contents:
node.alt = figcaption_el.contents[0] # type: ignore
else:
# 图片节点
node = ImageNode()
Expand Down

0 comments on commit 6f8293c

Please sign in to comment.