node.js功能由使用模块来实现
Node.js的功能都是需要使用api来实现的,这些api我们都称之为一个模块
url模块
- url: 处理url的一个模块
- parse: 将url字符转成url对象
- format: 将url对象转成url字符
- resolve: url路径的拼接,替换
- 案例:
const url = require( 'url' );
const urlStr = 'http://www.baidu.com:3000/home/food?a=1&b=2#hash=30';
const urlObj = url.parse( urlStr );
const str = url.format( urlObj )
// console.log(urlObj);
console.log(str);
/*
Url {
protocol: 'http:',
slashes: true,
auth: null,
host: 'www.baidu.com:3000',
port: '3000',
hostname: 'www.baidu.com',
hash: '#hash=30',
search: '?a=1&b=2',
query: 'a=1&b=2',
pathname: '/home/food',
path: '/home/food?a=1&b=2',
href: 'http://www.baidu.com:3000/home/food?a=1&b=2#hash=30' }
*/
// const urlStr = 'http://www.baidu.com/home/a'
// const url1 = url.resolve( urlStr,'../b')
// console.log( url1 );
http模块
-
三种数据请求方式:
- get
- request
- post
-
案例: 后端爬虫(爬虫: 爬去数据)
- 流程:后端数据请求 —》 数据分析 —》数据清洗 ----》 数据前台发送
- 爬虫: 并不是所有网站都能爬取的, 反爬虫的存在
- options 就是一个对象,也是一个配置