liveBook · Manning

HTML

As explained in The Quick Python Book, Fourth Edition

HTML is the HyperText Markup Language, a standard markup language for structuring documents and elements on the web.

HTML is a markup language for structuring web documents with nested elements, tags, text, attributes, and classes. Its structure can be represented as objects whose string conversion produces the complete document. section 15.14 section 22.4

Common HTML tasks include:

  • Representing an element hierarchy, such as html containing body and body containing p. section 15.14
  • Finding elements by tag, such as links represented by the a tag. section 22.4
  • Reading element text and attributes, such as a link’s text and href value. section 22.4
  • Selecting elements by class, such as elements with the special class. section 22.4

Parsing a page

Load HTML into Beautiful Soup, then query its structure: bs = bs4.BeautifulSoup(html, "html.parser"); a_list = bs("a"); a_item = a_list[0]; a_item.text returns 'link', while a_item["href"] returns the URL. bs.select(".special") finds elements carrying the special class. section 22.4

para = p(text="this is some body text")
doc_body = body(text="This is the body", subelement=para)
doc = html(subelement=doc_body)
print(doc)
 
<html>
<body>
This is the body
<p>
this is some body text
</p>
</body>
</html>

Shows a minimal nested HTML document and the generated string output, including html, body, and p elements. section 15.14

How The Quick Python Book, Fourth Edition covers it

How deep it goes
Explains nested elements, tags, classes, attributes, and parser queries, while stopping short of broad HTML syntax or browser behavior.
Examples
Uses nested html-body-p objects, a sample page with links and classes, and Beautiful Soup tag, attribute, and class queries.
What it assumes
Assumes general programming knowledge and introduces HTML through simplified nesting and parser examples.
What you can do after
Apply it via Beautiful Soup to parse HTML and extract tags, text, attributes, and class-selected elements.
How it connects
Connects HTML with HTML tags, HTML classes, Beautiful Soup, requests, regular expressions, and object-oriented programming.

Also explained in

Compare how 12 books explain HTML →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Quick Python Book, Fourth Edition. The section links point to the parts of the book it draws on.