url
url就是网址,比如http://www.baidu.com/20220728/news/page1/index.html?count=20&maxid=123456#top1等等都是url。
url的组成
网址的组成:协议、域名、pathname(路径)、querystring(查询字符串)、hash(哈希值)
url模块
在url模块中,我们主要用的是parse这个方法,也就是解析网址。
var url = require('url');
var adr = 'http://localhost:8080/default.html?year=2017&month=february';
var q = url.parse(adr, true);
//如果第一个值时第二个值默认是false
console.log(q)
console.log(q.host,typeof(q.host));
console.log(q.pathname,typeof(q.pathname));
console.log(q.search,typeof(q.search));
var qdata = q.query;
console.log(qdata,typeof(qdata))
console.log(qdata.month,typeof(q.month));
当parse第二个值是true时

当第二个值是false时

原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/277812.html