keeganstreet / element-finder Goto Github PK
View Code? Open in Web Editor NEWFind in Files with CSS selectors
Home Page: http://keegan.st/2012/06/03/find-in-files-with-css-selectors/
Find in Files with CSS selectors
Home Page: http://keegan.st/2012/06/03/find-in-files-with-css-selectors/
Cheerio runs 6 times faster in my initial tests. It also has fewer dependencies. The dependencies are JavaScript only which means users should have fewer installation problems.
Would be great to use Element Finder to select the content of an HTML element based on its CSS path.
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>
I'd like to execute the following
elfindiner -s "td.data" -t page.html
This would write the following to standard output:
Tabular Content 1
Tabular Content 2
E.g. .a .b
will incorrectly find 2 results in the following case:
<div class="a">
<div class="b">Should match</div>
<div class="autoclosed" />
</div>
<div class="b">Should not match</div>
Another interesting feature would be to normalize whitespace and eliminate new line characters from content. For example:
<td class="data">This is a comment
that a user made.</td>
By normalizing whitespace and eliminating new lines, you could obtain cleaner data:
<td class="data">This is a comment that a user made.</td>
The content of the element can then be extracted:
This is a comment that a user made.
For example:
cat filename.html | elfinder --normalize-whitespace --no-eol --extract-content --selector "td.data"
Hey there,
just tried you nifty little project but got an error in the knee...
/xxx/htdocs/node_modules/jsdom/lib/jsdom.js:250
window.document.documentElement.appendChild(script);
^
TypeError: Cannot call method 'appendChild' of null
at exports.env.exports.jsdom.env.processHTML (/xxx/htdocs/node_modules/jsdom/lib/jsdom.js:250:41)
at Array.forEach (native)
at exports.env.exports.jsdom.env.processHTML (/xxx/htdocs/node_modules/jsdom/lib/jsdom.js:233:18)
at Object.exports.env.exports.jsdom.env (/xxx/htdocs/node_modules/jsdom/lib/jsdom.js:262:5)
at processFile (/xxx/htdocs/node_modules/element-finder/element-finder.js:141:10)
at walk.extension (/xxx/htdocs/node_modules/element-finder/element-finder.js:172:5)
at /xxx/htdocs/node_modules/element-finder/element-finder.js:92:10
at /xxx/htdocs/node_modules/element-finder/element-finder.js:92:10
at /xxx/htdocs/node_modules/element-finder/element-finder.js:92:10
at /xxx/htdocs/node_modules/element-finder/element-finder.js:92:10
Simply running the script on a jekyll based project folder, with any selector.
Found 1 match in /master/_site/index.html
/Element Finder/lib/submodule-elfinder/node_modules/domtosource/app.js:73
throw new Error('The html and selector parameters are required');
^Error: The html and selector parameters are required
at Object.find (/Element Finder/lib/submodule-elfinder/node_modules/domtosource/app.js:73:10)
at processFile (/Element Finder/lib/submodule-elfinder/element-finder.js:179:27)
at walk.extension (/Element Finder/lib/submodule-elfinder/element-finder.js:231:5)
at /Element Finder/lib/submodule-elfinder/element-finder.js:107:10
at /Element Finder/lib/submodule-elfinder/element-finder.js:107:10
Unsure why?
Test cases are essential to know that the module runs correctly. These tests will need to be written before we switch over from JSDOM to Cheerio, so that we can be sure that the switch doesn't break Element Finder.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.