첫번째 방법
function updateSpreadsheet(cellRange) {
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName("Sheet1"); // Replace "Sheet1" with your sheet name
var blogUrl = "https://blog.google/..."; // Replace with your Google Blog post URL
var blogTitle = getBlogTitle(blogUrl);
var cell = sheet.getRange(cellRange); // Use the input cell range
cell.setValue(blogTitle);
}
function getBlogTitle(url) {
var response = UrlFetchApp.fetch(url);
var html = response.getContentText();
var title = html.match(/<title>(.*?)<\/title>/)[1];
return title;
}
1안의 단점을보안한
두번째 방법
function updateSpreadsheet(cellRange) {
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName("Sheet1"); // Replace "Sheet1" with your sheet name
var blogUrl = "https://blog.google/..."; // Replace with your Google Blog post URL
var blogTitle = getBlogTitle(blogUrl);
var range = sheet.getRange(cellRange); // Use the input cell range
range.setValue(blogTitle);
}
function getBlogTitle(url) {
var response = UrlFetchApp.fetch(url);
var html = response.getContentText();
var document = XmlService.parse(html);
var titleElement = document.getRootElement().getChild('head').getChild('title');
var title = titleElement.getText();
return title;
}
될랑가? 안될랑가? 나도 몰러, 적용해봐야 알제......딸국
어메~블로그 제목이 업데이트가 되는 것이 아니라 반대로 스프레드시트의 셀 내용이 블로그 제목으로 업데이트가 되아브렀네....ㅋㅋ....다음 코드로 봐꿔야 할 듯 허구만............딸국
ReplyDeletefunction updateBlogPostTitle() {
var spreadsheet = SpreadsheetApp.openById('시트 아이디');
var sheet = spreadsheet.getSheetByName('시트이름');
var title = sheet.getRange('셀1').getValue();
var subtitle = sheet.getRange('셀2').getValue();
var author = sheet.getRange('셀3').getValue();
var blogPostTitle = title + ' - ' + subtitle + ' by ' + author;
var blogId = '블로그아이디';
var postId = '포스트아이디';
var blog = Blogger.Blogs.get(blogId);
var post = Blogger.Posts.get(blogId, postId);
post.title = blogPostTitle;
var updatedPost = Blogger.Posts.patch(post, blogId, postId);
Logger.log('Updated blog post title: ' + updatedPost.title);
}
이것도 될지 안될지는 나도 몰러, 일단은 적용해 봐야 알 것이지만, 될 것 같은 느낌이구만.....딸국
This is a JavaScript code for a Google Apps Script function that updates the title of a blog post on Blogger.
DeleteThe function first opens a Google Spreadsheet by its ID, and then gets a specific sheet by its name. It then retrieves the values of three specific cells (셀1, 셀2, and 셀3) and stores them in separate variables.
Next, it concatenates the title, subtitle, and author into a new variable called blogPostTitle. This variable contains the new title for the blog post.
The function then retrieves the IDs of the blog and the specific post to be updated.
It then retrieves the original post from Blogger using the blog and post IDs, updates its title with the new value stored in the blogPostTitle variable.
Finally, the function uses the Blogger.Posts.patch method to update the post on the blog with the new title, and logs a message confirming the update.
Note that to use this code, you will need to replace '시트 아이디', '시트이름', '셀1', '셀2', '셀3', '블로그아이디', and '포스트아이디' with the appropriate values for your own spreadsheet, sheet, cells, blog, and post.