2017-09-11 64 views
-1

如何僅使用Node.js API獲取給定URL的文檔以使用。 這裏是我想出的一個片段:如何從節點j中的給定url獲取文檔對象

var needHttp = require('http'); 

var getAllFromSite = function (siteUrl, tag) 
{ 

var requestToURL = needHttp.get(siteUrl, function (responseFromURL) { 

responseFromURL. SOMEHOWgetDOCUMENT... 
    }); 

} 
+0

[讀數可能的複製內容從URL與Node.js](https://stackoverflow.com/questions/6287297/reading-content-from-url-with-node-js) – lumio

回答

0

到目前爲止,我發現這一點,但它仍然需要的DOMParser,我便無法找到:

function getSourceAsDOM(url) 
{ 
xmlhttp=new XMLHttpRequest(); 
xmlhttp.open("GET",url,false); 
xmlhttp.send(); 
parser=new DOMParser(); 
return parser.parseFromString(xmlhttp.responseText,"text/html"); 
} 
相關問題