节点 | urlObject.search API
Node 中的urlObject.search()
方法用于获取主机名内的搜索查询,后跟“?”字符。
Syntax : urlObject.search()
Return : Returns the search query after ‘?’ character.
示例 #1:在这些示例中,我们展示了urlObject.search()
方法如何能够从主机名中提取搜索查询。
// Importing the module 'url'
const url = require('url');
var adr =
'http://localhost:8080/default.htm?year=2019&month=may';
// Parse the address:
var q = url.parse(adr, true);
/* The parse method returns an object containing
URL properties */
console.log(q.search);
输出 :
示例#2:
// Importing the module 'url'
const url = require('url');
var adr =
'http://localhost:8080/default.htm?year=2k19&month=geekofthemonth';
// Parse the address:
var q = url.parse(adr, true);
/* The parse method returns an object containing
URL properties */
console.log(q.search);
输出 :