How to use JQuery selectors in Node.js

后端 未结 4 1525
梦谈多话
梦谈多话 2021-02-06 05:16

I\'m trying to extract email info from HTML files in my hard drive.

If I load the file in firefox and run jQuerify bookmarklet I can use successfully the following selec

4条回答
  •  忘了有多久
    2021-02-06 05:39

    It's tough to use jquery with node.js but it's possible. Here's an implementation with jsdom:

    var jsdom = require('jsdom').jsdom,
        sys = require('sys'),
        window = jsdom().createWindow();
    
    jsdom.jQueryify(window, '/path/to/jquery.js', function (window, jquery) {
      window.jQuery('body').append("
    Hello World
    "); sys.puts(window.jQuery(".testing").text()); // outputs Hello World });

    For more info see:

    http://blog.nodejitsu.com/jsdom-jquery-in-5-lines-on-nodejs

    or:

    Can I use jQuery with Node.js?

提交回复
热议问题