1
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Google Apps ScriptでスプレッドシートにサイトのURLを記入する方法

Last updated at Posted at 2017-06-20
getTitle
function getTitle(tURL) {
  var objSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var objSheet = objSpreadsheet.getActiveSheet();
  var objCell = objSheet.getActiveCell();
  var response = UrlFetchApp.fetch(tURL);

  var myRegexp = /<title>([\s\S]*?)<\/title>/i;
  var match = myRegexp.exec(response.getContentText());
  var title = match[1];

  title = title.replace(/(^\s+)|(\s+$)/g, "");  
  //objCell.setValue(title)
  if(title==null){
    return "NULL";
  }else{
    return title;    
  }
}
getDescription
function getDescription(tURL) {
  var objSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var objSheet = objSpreadsheet.getActiveSheet();
  var objCell = objSheet.getActiveCell();
  var response = UrlFetchApp.fetch(tURL);

  var myRegexp = /<meta name=\"description\" .*content=\"([\s\S]*?)(\".*\/|\".*)>/i;
  var match = myRegexp.exec(response.getContentText());
  var title = match[1];

  title = title.replace(/(^\s+)|(\s+$)/g, "");  
//  objCell.setValue(title)
  if(title==null){
    return "NULL";
  }else{
    return title;    
  }
}
1
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?