Tag
The Tag
object represents different tags of HTML and XML documents. The creation of Tag
objects is done when parsing the documents. The different HTML/XML tags identified during parsing are represented as corresponding Tag
objects and these objects will have attributes and contents of the HTML/XML tag. The Tag
objects can be used for searching and navigation within the HTML/XML document.
Accessing the Tag object from BeautifulSoup
BeautifulSoup
allows us to access any Tag
object. For example, we can access the first occurrence of the <a>
tag in the next example by simply calling the name of the tag <a>
.
html_atag = """<html><body><p>Test html a tag example</p> <a href="http://www.packtpub.com'>Home</a> <a href="http;//www.packtpub.com/books'>Books</a> ...
Get Getting Started with Beautiful Soup now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.