์นด์นด์ค๋ทฐ ์๋๋ฐํ์ ํ๋ ค๋ค ๋ณด๋ ์ด๋ค ์ฝํ ์ธ ๋ฅผ ๊ฐ์ ธ์์ผ ํ ์ง ๊ณ ๋ฏผํ๋ค. ๊ธฐ์กด๊น์ง ์๋์ผ๋ก ํ๋ ๋ณด๋ ๋ฐํ์ ํธ๋ฆฌํ๊ฒ ํ๊ณ ์ถ์๋ค. ๊ทธ๋์ ์๋ ๋ฐํ์ ์๊ฐํด๋ณด๊ธฐ๋ก ํ์๋ค.
1. ์ฝํ ์ธ : ๋ค์ด๋ฒ , ๋ค์ ๋ด์ค, ์์ฑํ ํฐ์คํ ๋ฆฌ, ์์ฑํ ๋ธ๋ก๊ทธ ์ฝํ ์ธ
2. Tool : ๋๊ตฌ๋ ์ฌ์ฉํ ์ ์๋ ๊ตฌ๊ธ ์คํ๋ ๋์ํธ ๋ฐ ๊ตฌ๊ธ ์ฑ์คํฌ๋ฆฝํธ
๊ฒฐ๊ณผ๋ฌผ
๋ค์ด๋ฒ ๋ด์ค ๊ฐ์ ธ์ค๊ธฐ
- ๋ค์ด๋ฒ open API ์ฌ์ฉ ์ ์ฒญ : https://developers.naver.com/apps/#/register?defaultScope=search
- ์ ์ฒญํ client ID , client secret ์ ๋ณด๋ฅผ ๊ฐ์ ธ์จ๋ค.
- ๊ตฌ๊ธ ์คํ๋ ๋ ์ํธ๋ฅผ ์ด๊ณ , app script๋ฅผ ์คํํ๋ค.
- ์๋ ์์ค๋ฅผ ์ฌ์ฉํ์ฌ ์ ์ฅํ๊ณ ์คํ์ํจ๋ค.
function naverNews(searchWord) {
var client_key = "๊ฐ์ธ KEY";
var client_secret = "๊ฐ์ธ SECRET";
var url = "https://openapi.naver.com/v1/search/news.json?query=" + searchWord
var response = UrlFetchApp.fetch(url,{'method' : 'GET',
'headers': {
'X-Naver-Client-Id' : client_key,
'X-Naver-Client-Secret' : client_secret
}
});
var resData = response.getContentText();
resData = JSON.parse(resData);
var arrTitle = new Array();
var arrDescription = new Array();
var arrLink = new Array();
var arrDate = new Array();
console.log(resData);
for(var i = 0 ; i < 1 ; i ++ )
{
arrTitle.push(replaceTitle(resData.items[i].title));
arrLink.push(resData.items[i].link);
arrDescription.push(replaceTitle(resData.items[i].description));
arrDate.push(resData.items[i].pubDate);
}
var arrInfo = new Array();
arrInfo.push(arrTitle);
arrInfo.push(arrLink);
arrInfo.push(arrDescription);
arrInfo.push(arrDate);
//์คํ๋ ๋์ํธ์ ์ธ๋ก๋ก ์ถ๋ ฅํ๊ธฐ ์ํด ...
var transposed = Array.from({ length: arrTitle.length }, () => new Array().fill(0))
for (var o=0; o< arrInfo.length; o++) {
for (var v=0; v<arrInfo[0].length; v++) {
[transposed[v][o]] = [arrInfo[o][v]];
}
}
return transposed;
}
- ๊ตฌ๊ธ ์คํ๋ ๋ ์ํธ์์ ์์ฑํ ํจ์๋ฅผ ํธ์ถํ๋ค. C1์ ์ ์์น๋ฅผ ์๋ฏธํ๋ฉฐ ๊ด์ฌ ํค์๋๋ฅผ ์ ๋ ฅํ๋ฉด ๋๋ค (์ : ์ฐ์)
์นด์นด์ค ์น ๋ฌธ์ ๊ฐ์ ธ์ค๊ธฐ
- ์นด์นด์ค REST API ์ฌ์ฉ ์ ์ฒญ : https://developers.kakao.com/console/app
- ์์ฑํ ์ ํ๋ฆฌ์ผ์ด์ > ์ฑ ์ค์ > ์ฑ ํค
- ์๋ ์์ค๋ฅผ ๋ค์ด๋ฒ ์ ์์ค์ ๊ฐ์ด ์ ์ฅํ์ฌ ์คํํ๋ค
function DaumNews(searchWord) {
var REST_API_KEY = '๊ฐ์ธ KEY';
for ( var p=1; p<5 ; p++)
{
var url = "https://dapi.kakao.com/v2/search/web?query=" + searchWord + '&page='+ p +'&size=10&sort=recency'
var response = UrlFetchApp.fetch(url,{'method' : 'GET',
'headers': {
'Authorization' : 'KakaoAK ' + REST_API_KEY
}
});
var resData = response.getContentText();
resData = JSON.parse(resData);
var arrTitle = new Array();
var arrLink = new Array();
var arrContent = new Array();
var arrDate = new Array();
for(var i = 0 ; i < 1 ; i ++ ){
if(resData.documents[i].url.indexOf("wiki") == -1 && resData.documents[i].url.indexOf("html") == -1)
{
arrTitle.push(replaceTitle(resData.documents[i].title));
arrLink.push(resData.documents[i].url);
arrContent.push(replaceTitle(resData.documents[i].contents));
arrDate.push(resData.documents[i].datetime);
}
}
var arrInfo = new Array();
arrInfo.push(arrTitle);
arrInfo.push(arrLink);
arrInfo.push(arrContent);
arrInfo.push(arrDate);
}
var transposed = Array.from({ length: arrTitle.length }, () => new Array().fill(0))
for (var o=0; o< arrInfo.length; o++) {
for (var v=0; v<arrInfo[0].length; v++) {
[transposed[v][o]] = [arrInfo[o][v]];
}
}
return transposed;
}
function replaceTitle(title){
var tempTitle = "";
tempTitle = title.replaceAll(""","")
tempTitle = tempTitle.replaceAll(""","");
tempTitle = tempTitle.replaceAll("&","")
tempTitle = tempTitle.replaceAll("<b>","");
tempTitle = tempTitle.replaceAll("</b>","")
tempTitle = tempTitle.replaceAll("'","");
tempTitle = tempTitle.replaceAll("<","");
tempTitle = tempTitle.replaceAll(">","");
tempTitle = tempTitle.replaceAll(" "," ");
return tempTitle;
}
- ๊ตฌ๊ธ ์คํ๋ ๋ ์ํธ์์ ์์ฑํ ํจ์๋ฅผ ํธ์ถํ๋ค.
๋ค์ด๋ฒ๋ ๋ค์์ด๋ ์ง์ง ์ค์ํ ๋ถ๋ถ์ ์ด ๋ถ๋ถ์ ํด๋น ๋๋ค. ๋จ ๋ช ์ค๋ก ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ฌ ์ ์๋ค. ๋ค์์ ์น๋ฌธ์๋ ์ถํ ์ต์ ์ ๋ ฌํ๋ ๋ฐฉ๋ฒ๊น์ง ์ถ๊ฐํด๋ณด๊ฒ ๋ค.
var url = "https://openapi.naver.com/v1/search/news.json?query=" + searchWord
var response = UrlFetchApp.fetch(url,{'method' : 'GET',
'headers': {
'X-Naver-Client-Id' : client_key,
'X-Naver-Client-Secret' : client_secret
}
});
var resData = response.getContentText();
resData = JSON.parse(resData);
ํฐ์คํ ๋ฆฌ ๊ฒ์๊ธ ํ์ดํ๊ณผ ๋งํฌ ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ์ ๋ค์ ํธ ๐
๋๊ธ