0

i need to get the page name of a google sites with google apps script, there is another post about it but is about URL such as Retrieve page title from URL in Apps Script, but i need to get the page title name.

Thanks.

Rubén
  • 34,714
  • 9
  • 70
  • 166
Luis Arcos
  • 11
  • 1
  • That article you refer to actually says that you want to parse the html: "If you want to get the title of the page at a 'normal' URL, then you can get the contents of the page using UrlFetchApp.fetch(url) and then parse the title tag." – Stan Nov 03 '16 at 19:19

2 Answers2

0

If you are in a domain, use the following, replacing teh strings as appropriate.

var site = SitesApp.getSite("mydomainname.org", "sitename");
var page = site.getChildren()[0];
var title = page.getTitle();

Karl

Karl_S
  • 3,364
  • 2
  • 19
  • 33
0

As per this stackoverflow answer, the function works well for getting page title.

function betweenMarkers(text, begin, end) {
  var firstChar = text.indexOf(begin) + begin.length;
  var lastChar = text.indexOf(end);
  var newText = text.substring(firstChar, lastChar);
  return newText;
}

var pageTitle = betweenMarkers(response.getContentText(),"<title>","</title>")
console.log(pageTitle)
Rajesh Swarnkar
  • 601
  • 1
  • 6
  • 18