Skip to main content
100%

Third title

✓ Published0🌍 Public
IIanHopkinson
Last edited Nov 24, 2015
Created on Nov 24, 2015

This example demonstrates how to use XPath queries with lxml to extract data from both HTML and XML documents. It shows techniques for selecting elements by tag name, attribute values, and text content, as well as navigating the document tree with axes like `following-sibling` and the `..` operator. The code uses `lxml.html.fromstring` and `lxml.etree.fromstring` to parse content fetched from a live website and a hardcoded XML sample, respectively. It highlights namespace handling in XML, showing that prefixed queries require explicit namespace mapping, while unprefixed queries fail without a default namespace binding. The example also illustrates retrieving attribute values like `setCount` and iterating over all elements with `getiterator`.

AI-generated description

Similar vizzes