Dan Jenson
Dan Jenson

Reputation: 1041

Extract all text from sub-element of XML tree in Python

I am trying to extract the section of government bill data, such as this https://www.govtrack.us/data/congress/113/bills/sconres/sconres14/text-versions/is/document.xml. I only want the text from the section, but can't figure how how to navigate to it using python's xml.etree.ElementTree; the equivalent javascript would be something like getElementbyTagName.

Upvotes: 0

Views: 434

Answers (1)

har07
har07

Reputation: 89285

In xml.etree.ElementTree, you can use findall() passing XPath expression string as parameter, to find elements with certain criteria. So, for simple element names (those that doesn't contain prefix), the equivalent of Javascript's getElementbyTagName("elementName") in ElementTree would be findall(".//tagName").

Upvotes: 1

Related Questions