美文网首页
nodejs环境使用jquery解析html的方法

nodejs环境使用jquery解析html的方法

作者: TOPro | 来源:发表于2020-11-05 23:57 被阅读0次

原文
https://www.darklaunch.com/parse-html-string-with-node-js-jquery-and-jsdom.html

安装

yarn add jsdom jquery

--

var jsdom = require('jsdom');  
var dom =  new jsdom.JSDOM();  
var window = dom.window;  
var document = window.document; 
var $ = require('jquery')(window); 
console.log('version:', $.fn.jquery);  
var $content = $('<p><a href="[https://www.example.com/](https://www.example.com/)">Link</a></p>'); 
console.log('text:', $content.text()); 
console.log('html:', $content.html());
console.log('href:', $content.find('a').attr('href'));

相关文章

网友评论

      本文标题:nodejs环境使用jquery解析html的方法

      本文链接:https://www.haomeiwen.com/subject/ybszvktx.html