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
中使用tweetDisplayName
在python中添加BeautifulSoup
标记。有人知道吗?
答案 0 :(得分:0)
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)