If you set a tag’s .string attribute, the tag’s contents are replaced with the string you give:
markup = '<a href="http://example.com/">I linked to <i>example.com</i></a>'
soup = BeautifulSoup(markup)
tag = soup.a
tag.string = "New link text."
tag
# <a href="http://example.com/">New link text.</a>
Be careful: if the tag contained other tags, they and all their contents will be destroyed.
使用
find()
搜索id=test
查找要修改的标记。然后:BeautifulSoup Documentation - "Modifying the tree"
相关问题 更多 >
编程相关推荐