我在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