获取网页源代码
node 获取网页源代码
var http = require'http');
var url = "http://www.baidu.com/";
// 参数url 和 回调函数
http.geturl, function res) {
var html = '';
// 绑定data事件 回调函数 累加html片段
res.on'data', function data) {
html += data;
});
res.on'end', function ) {
console.loghtml);
});
}).on'error', function ) {
console.log'获取数据错误');
});
jquery 获取网页源代码
$.getwindow.location.href,functionres){
console.logres);
});
原生 js 获取网页源代码
// 这个获取到的是被解析过的 html, 并且没有 <!DOCTYPE html>
document.documentElement.outerHTML
