Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Server-side jquery

Server-side jquery

Problem

Say I have a script written in perl or python. What's the easiest way to write a function that would use Jquery selectors on strings as part of it? i.e. to be able to do:

jquery_selector('table.new#element', text)

where jquery_selector is a function that runs a jquery selector on the html string stored in text. Even if it was just limited to returning strings (not full jquery objects), it would still be really useful. i.e. if you were required to give a javascript function as a callback which would render the results to something comprehensible in the scripting language:

jquery_selector('table.new#element, text, 'function(e){return e.val()}')

And it would return the results of the callback as a list.

I realize that there are dom libraries for most languages, but jquery is so much better than most of them.

I am not asking about native libraries which have a syntax like jquery. I guess what would be needed is an API to a browser which jquery would run on? Or is this what node.js does?

Problem courtesy of: fastmultiplication

Solution

if i understand your question correctly you want is something like phantom.js. PhantomJS is a headless WebKit with JavaScript API. you can inject jquery into it and use all the Jquery Selectors to manipulate the dom. you can make it work like a standalone server aswell.

Solution courtesy of: Kishore

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Server-side jquery

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×