📜  tag inside tag beautifulsoup - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:18.487000             🧑  作者: Mango

代码示例1
html = """
  • protocol
  • """ soup = BeautifulSoup(html, "lxml") a = soup.select_one("div[class=pr]") # Li parent parent = soup.new_tag("li", class_="parent") # Child anchor child = soup.new_tag("a", href="hm/test", class_="child") child.string = 'TEST' # Append child to parent parent.append(child) # Insert parent a.insert_after(parent) print(soup.prettify())