I have many html pages on my computer
and I want to write a javascript script to harvest those pages for some text/elements
(see extract elements from a html page)
someone has write some jquery codes, which can extract the elements I want, but I don’t know how to run the scripts over html pages on linux console and put the extracted elements into log files
so basically I want to run like:
javascript.js page1.html
javascript.js page2.html
javascript.js page3.html
besides, is it possible to use javascript to write to some files?
BTW, I’M on linux
thanks!
There are a handful of ways to run Javascript at the command-line.
If you’re on Windows, you can write
WSH-style shell scripts in JS. Done!If you’re on Mac/Linux, all you need is a command-line JS parser. I’ve tried a few and I like
V8the best, though getting it compiled is a bit of a pain.The part about using jQuery makes very little sense, though, because jQuery is primarily intended to provide shortcuts into the DOM of a web page.
So, if what you’re really hoping to do is run a script against several HTML files, and query their DOMs, it might be time to look at
Webdriver, althoughPhantomjsis probably a much easier place to start.