Skip to content

cheeriovsuntangle

MIT 51 13 28,045
34.5 million (month) Oct 08 2011 1.0.0-rc.12(8 months ago)
609 2 24 MIT
Jun 09 2011 142.0 thousand (month) 1.2.1(2 years ago)

cheerio is a popular JavaScript library that allows you to interact with and manipulate HTML and XML documents in a similar way to how you would with jQuery in a browser. It is a fast, flexible, and lean implementation of core jQuery designed specifically for the server.

One of the main benefits of using cheerio is that it allows you to use jQuery-like syntax to navigate and m anipulate the Document Object Model (DOM) of an HTML or XML document, making it easy to work with.

cheerio supports CSS selectors though not XPath.

untangle is a simple library for parsing XML documents in Python. It allows you to access data in an XML file as if it were a Python object, making it easy to work with the data in your code.

To use untangle, you first need to install it via pip by running pip install untangle``. Once it is installed, you can use theuntangle.parse()`` function to parse an XML file and create a Python object.

For example:

import untangle

obj = untangle.parse("example.xml")
print(obj.root.element.child)

You can also pass a file-like object or a string containing XML data to the untangle.parse() function. Once you have an untangle object, you can access elements in the XML document using dot notation.

You can also access the attributes of an element by using attrib property, eg. `obj.root.element['attrib_name']`` untangle also supports xpath-like syntax to access the elements, obj.root.xpath("path/to/element")

It also supports iteration over the elements using obj.root.element.children

for child in obj.root.element.children:
    print(child)

Example Use


const cheerio = require('cheerio');
const $ = cheerio.load('<html><head><title>My title</title></head><body><h1 class='name'>Hello World!</h1></body></html>');
// use css selectors
console.log($('title').text()); // My title
console.log($('.name').text()); // Hello World!

// select multiple elements
const $ = cheerio.load('<html><body><ul><li>item 1</li><li>item 2</li></ul></body></html>');
$('li').each(function(i, elem) {
  console.log($(this).text());
});

// modify elements
const $ = cheerio.load('<html><body><h1>Hello World!</h1></body></html>');
$('h1').text('Hello, Cheerio!');
console.log($.html());
import untangle

obj = untangle.parse("example.xml")

print(obj.root.element.child)
# access attributes:
print(obj.root.element['attrib_name'])
# use xpath:
element = obj.root.xpath("path/to/element")

Alternatives / Similar


Was this page helpful?