views:

57

answers:

5

Just out of curiosity, I am trying to see if it is possible to use jQuery to read a HTML file so that I can use it to output some values of some html elements? I am looking for some functionality like what Firebug provides i.e. Firebug lets me use the $() on any webpage so what I am trying to achieve is:

  • I have a bunch of HTML files
  • I need to load each one of them and using jQuery, I want to extract some information pertaining to some HTML elements

So maybe use Python to load each file and then use jQuery to parse the HTML somehow. I don't know the right terminology to use to describe this requirement but any suggestions? Maybe I am looking for a command line jQuery execution engine?

EDIT: Or maybe I'm looking for a scripting language that provides the $() functionality. I looked at Beautiful Soup but I'm still curious about jQuery like functionality.

+1  A: 

Perhaps take a look at lxml? The lxml.cssselect submodule allows you to select objects in a manner very similar to jQuery's selectors.

Amber
A: 

If you are using python then probably beautiful soup is a better solution

http://www.crummy.com/software/BeautifulSoup/

lisa
+1  A: 

Maybe I'll get another answer but I just found the closest match here:

http://pypi.python.org/pypi/pyquery

It looks awesome as of now.

Legend
The awesome power of Google :)
mootinator
A: 

I've used PHP: dom quite successfully for scraping webpages. For simple data extraction getElementById and getElementByTagName are usually plenty powerful enough.

mootinator
A: 

Try this:

http://www.dotnetspeaks.com/DisplayArticle.aspx?ID=70

Sumit