---
# System prepended metadata

title: Problem set 2(蕭定豪)

---

```python=
def get_poems(html_source):
    # 將輸入的HTML源碼分割成行
    lines = html_source.split('\n')

    # 用於儲存提取的詩行的列表
    poem_lines = []

    # 遍歷每一行
    for line in lines:
        # 移除首尾的空格
        line = line.strip()

        # 如果行以"<td>"開頭且以"</td>"結尾，說明它包含詩行內容
        if line.startswith("<td>") and line.endswith("</td>"):
            # 去除"<td>"和"</td>"標籤，提取詩行內容
            poem_line = line.replace("<td>", "").replace("</td>", "")
            # 將提取的詩行添加到列表中
            poem_lines.append(poem_line)

    # 將提取的詩行用逗號連接起來
    poem = "，".join(poem_lines)

    # 將逗號替換為句號和換行符，以符合輸出要求
    poem = poem.replace("，", "。\n")

    # 返回最終的詩
    return poem
```

執行截圖
![](https://hackmd.io/_uploads/ry1T2e6t3.png)

I tried my best, but error...


ChatGPT詢問過程:
https://chat.openai.com/share/d128f603-573f-4f47-bbd6-6aa00e0ef26f