=IMPORTXML("웹페이지 URL", "XPath 표현식")=IMPORTXML("https://finance.naver.com/marketindex/", "//span[@class='value']")=IMPORTHTML("웹페이지 URL", "table" 또는 "list", 테이블/목록 번호)=IMPORTHTML("[https://en.wikipedia.org/wiki/List_of_countries_by_population_(United_Nations)](https://en.wikipedia.org/wiki/List_of_countries_by_population_(United_Nations))", "table", 1)=IMPORTDATA("데이터 URL")=IMPORTDATA("http://www.example.com/data.csv")function fetchData() {
const url = "https://m.stock.naver.com/marketindex/metals/M04020000";
const response = UrlFetchApp.fetch(url);
const html = response.getContentText();
// 정규식으로 데이터 추출
const regex = /<strong class="DetailInfo_price__InDYQ">([\d,]+)<\/strong>/;
const match = html.match(regex);
if (match && match[1]) {
const price = match[1].replace(/,/g, ""); // 쉼표 제거
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("금시세") || SpreadsheetApp.getActiveSpreadsheet().insertSheet("금시세");
sheet.getRange(1, 1).setValue(`금 시세: ${price}`);
} else {
Logger.log("데이터를 가져오지 못했습니다.");
}
}function fetchAPIData() {
const url = "https://api.example.com/data";
const options = {
method: "get",
headers: {
"Authorization": "Bearer YOUR_API_KEY"
}
};
const response = UrlFetchApp.fetch(url, options);
const data = JSON.parse(response.getContentText());
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("API 데이터") || SpreadsheetApp.getActiveSpreadsheet().insertSheet("API 데이터");
sheet.getRange(1, 1).setValue(data.someKey);
}