Just create an empty BeautifulSoup()
object:
soup = BeautifulSoup()
and start adding elements:
soup.append(soup.new_tag("a", href="http://www.example.com"))
For XML you could start out with a XML header by using the xml
tree builder:
soup = BeautifulSoup(features='xml')
This requires lxml to be installed first. This sets the .is_xml
flag on the BeautifulSoup
object (which can also be set manually).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…