jsdom模块应用
1 | var jsdom = require("jsdom"); |
或者:1
2
3
4
5
6
7
8var jsdom = require("jsdom");
jsdom.env('
<p><a class="the-link" href="https://github.com/tmpvar/jsdom">jsdom!</a></p>',
["http://code.jquery.com/jquery.js"],
function(errors,window){
console.log("contents of a.the-link:",window.$("a.the-link").text());
}
);
第一个参数是抓取的url地址。第二个是你的jq代码。第三个就是回调方法。传给你的window就是一个包含url所连接的内容的全新window.可以在window.\$() 选择器下查找任何你想要的元素。