html_xpath 2.0.2

SDKdartflutter
Platformandroidioswindowslinuxmacosweb

xpath package for dart, uses a path expression to select node or a list of nodes from an HTML document.

html_xpath

Pub support

XPath selector based on html.

Null safety version of xpath_parse

Get started

Add dependency

dependencies:
  xpath_parse: lastVersion

Super simple to use

final String html = '''
<html lang="en">
<div><a href='https://github.com'>github.com</a></div>
<div class="head">head</div>
<table>
    <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
        <td>4</td>
    </tr>
</table>
<div class="end">end</div>
</html>
''';

XPath.source(html).query("//div/a/text()").list()

more simple refer to this

Syntax supported:

NameExpression
immediate parent/
parent//
attribute[@key=value]
nth childtag[n]
attribute/@key
wildcard in tagname/*
functionfunction()

Extended syntax supported:

These XPath syntax are extended only in Xsoup (for convenience in extracting HTML, refer to Jsoup CSS Selector):

NameExpressionSupport
attribute value not equals[@key!=value]√
attribute value start with[@key~=value]√
attribute value end with[@key$=value]√
attribute value contains[@key*=value]√
attribute value match regex[@key~=value]√