xpath_for_html 1.0.1 copy "xpath_for_html: ^1.0.1" to clipboard
xpath_for_html: ^1.0.1 copied to clipboard

discontinuedreplaced by: xpath_selector
outdated

xpath package for HTML, most XPath syntax is supported.

xpath_for_html #

Pub

An XPath selector for locating HTML elements

English | 中文文档

Easy to use #

You have three ways to do XPath queries


final html = '''<html><div></div></html>''';
final htmlDom = parse(htmlString).documentElement!;

// Create by html string

final result1 = XPath.html(html).query('//div');

// Or through the dom of the HTML package
final result2 = XPath(htmlDom).query('//div');

// Or query directly through element
final result3 = htmlDom.queryXPath('//div');

// Get all nodes of query results
print(result1.elements);

// Get the first node of query results

print(result1.element);

// Get all properties of query results
print(result1.attrs);

// Get the first valid property of the query result (not null)
print(result1.attr);

More examples can be referred toexample or test

Basic syntax #

Expression Css or html Description Attr
// Selects nodes in the document from the current node that match the selection no matter where they are
/ Selects from the root node
.. Selects the parent of the current node
tag[n] nth-child(n) Select by index
tag[@key="value"] tag[key="value"] Filter properties
node() .children child
text() .text text
@attr Selects attributes

For more syntax, please refer toXPath

Extended syntax #

In the attribute selector, the parser extends the following attribute selector in CSS style

Expression Css Description
[@attr='value'] [attr="value"] Selects all elements with attr="value"
[@attr~='value'] [attr~="value"] Selects all elements attribute containing the word "value"
[@attr^='value'] [attr^="value"] Selects all elements whose attr attribute value begins with "value"
[@attr$='value'] [attr$="value"] Selects all elements whose attr attribute value ends with "value"
[@attr*='value'] [attr*="value"] Selects all elements whose attr attribute value contains the substring "value"
0
likes
140
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

xpath package for HTML, most XPath syntax is supported.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

expressions, html

More

Packages that depend on xpath_for_html