ch04_test1.js
var url =require('url'); var urlStr ="https://search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=1&ie=utf8&query=Popcorn"; //문자를 parse 객체로 변환 var curUrl=url.parse(urlStr); console.log(curUrl); console.log('query - > ' + curUrl.query); console.log("------------------------------------"); //원본 url 주소와 같아지게 하는 방법 var curStr =url.format(curUrl); console.log('url - > ' +curStr); console.log("------------------------------------"); // querystring 모듈 불러오기 var querystring=require('querystring'); var params=querystring.parse(curUrl.query); console.log('검색어 : ' + params.query);
Command: node "C:/Program Files (x86)/Brackets/www/macaronics2/ch04_test1.js"
Working directory: C:/Program Files (x86)/Brackets/www/macaronics2/
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'search.naver.com',
port: null,
hostname: 'search.naver.com',
hash: null,
search: '?where=nexearch&sm=top_hty&fbm=1&ie=utf8&query=Popcorn',
query: 'where=nexearch&sm=top_hty&fbm=1&ie=utf8&query=Popcorn',
pathname: '/search.naver',
path: '/search.naver?where=nexearch&sm=top_hty&fbm=1&ie=utf8&query=Popcorn',
href: 'https://search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=1&ie=utf8&query=Popcorn' }
query - > where=nexearch&sm=top_hty&fbm=1&ie=utf8&query=Popcorn
------------------------------------
url - > https://search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=1&ie=utf8&query=Popcorn
------------------------------------
검색어 : Popcorn
Program exited with code 0
댓글 ( 4)
댓글 남기기