Html 如何在python中使用Beauty soup添加li标记
我需要在python中使用BeautifulSoup在tweetDisplayName之后添加li标记。有人知道吗?重复,Html 如何在python中使用Beauty soup添加li标记,html,python-2.7,beautifulsoup,html-lists,Html,Python 2.7,Beautifulsoup,Html Lists,我需要在python中使用BeautifulSoup在tweetDisplayName之后添加li标记。有人知道吗?重复, from bs4 import BeautifulSoup soup = BeautifulSoup(""" <html> <body> <ul> <li>tweetDisplayName</li> </br>
from bs4 import BeautifulSoup
soup = BeautifulSoup("""
<html>
<body>
<ul>
<li>tweetDisplayName</li>
</br>
<li>Link:<a href="tweetLink">tweetLink</a></li>
</br>
</ul>
</p>
</body>
</html>
""")
li_new = soup.new_tag("li")
li_new['class'] = 'cls'
li_new.append("content")
li_element = soup.find_all('li', text='tweetDisplayName')[0]
li_element.insert_after(li_new)