我在NodeJS中使用JQuery npm尝试处理某些HTML。但我似乎无法得到最终的HTML作为文本发送与http模块的管道。我可以得到$html.find('head')
以生成html文本,但$html.find('html')
和所有其他解决方案产生一个对象。如何更改和检索HTML文档
这里是我的代码:
// this code, which will run under nodejs using jquery, should update the head in an entire html document
var $ = require('jquery');
var $html = $('<html><head><title>this should be replaced</title></head><body>and the entire document should be available as text</body></html>');
console.log('html', $html);
var $body = $html.find('body');
var res = $html.find('head').replaceWith('<head><title>with this</title></head>');
console.log(res.html());
的感谢!
顺便说一句,'$ html.find('head')'不会产生任何HTML文本。 – 2013-03-13 19:27:52