NodeJS 获取网页源代码
2023-09-11 14:17:02 时间
获取网页源代码
node 获取网页源代码
var http = require('http');
var url = "http://www.baidu.com/";
// 参数url 和 回调函数
http.get(url, function (res) {
var html = '';
// 绑定data事件 回调函数 累加html片段
res.on('data', function (data) {
html += data;
});
res.on('end', function () {
console.log(html);
});
}).on('error', function () {
console.log('获取数据错误');
});
jquery 获取网页源代码
$.get(window.location.href,function(res){
console.log(res);
});
原生 js 获取网页源代码
// 这个获取到的是被解析过的 html, 并且没有 <!DOCTYPE html>
document.documentElement.outerHTML
相关文章
- nodejs - fs模块 - 文件操作
- nodejs发送请求
- [NodeJS] Deploy a Node Application with the Now CLI
- electron 调用nodejs native c++ addon
- nodejs npm常用命令
- 用node-inspector调试NodeJS
- Verdaccio介绍及安装 -- nodejs私有npm proxy registry代理
- 使用nodejs代码在SAP C4C里创建Individual customer
- nodejs里socket.on和socket.once的单步调试
- ActiveMQ 入门Nodejs版
- Node.js学习笔记(四)——NodeJS访问MongoDB与MySQL数据库
- 第一个nodejs程序,helloworld解析
- 【Nodejs】深入理解Express框架之如何使用各类中间件_04