14
5
Question
What tool (preferably for Linux) can select the content of an HTML element based on its CSS path?
Example
For example, consider the following HTML document:
<html>
<body>
<div class="header">
<h1>Header</h1>
</div>
<div class="content">
<table>
<tbody>
<tr><td class="data">Tabular Content 1</td></tr>
<tr><td class="data">Tabular Content 2</td></tr>
</tbody>
</table>
</div>
<div class="footer">
<p>Footer</p>
</div>
</body>
</html>
What command-line program (e.g., a kind of "cssgrep") can extract values using a CSS selector? That is:
cssgrep page.html "body > div.content > table > tbody > tr > td.data"
The program would write the following to standard output:
Tabular Content 1
Tabular Content 2
Related Links
- https://getfirebug.com/wiki/index.php/Command_Line_API#.24.24.28selector.29
- https://stackoverflow.com/questions/7334942/is-there-something-like-a-css-selector-or-xpath-grep
- https://github.com/keeganstreet/element-finder
- http://www.w3.org/Tools/HTML-XML-utils/
Thank you!
2For macOS users,
brew install html-xml-utils
. – anishpatel – 2018-05-05T20:11:26.220