先记住这张图
官方文档
const url = require('url');
let urlString = 'https://v.youku.com/v_show/id_XNDM4OTQ0OTI0.html?spm=a2h0k.11417342.soresults.dplaybutton&lang=%E8%8B%B1%E8%AF%AD'
let urlObj=url.parse(urlString) // url字符串转为对象
console.log(urlObj)
console.log('--------------分割线---------------')
console.log(urlObj.host)
console.log('--------------分割线---------------')
let string = url.format(urlObj) // 对象装url字符串
console.log(string)
输出结果
网友评论