Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
94 views
in Technique[技术] by (71.8m points)

javascript - Webpage Word & Keyword Count Google Apps Script

I am hoping to update a script to a Google Apps Script project that will provide me with the word count for an inputted website.

I have some code that helps me get this for a google doc but not quite a website. I would prefer to run the function in relation to a URL input in a cell and get the word count of that URL.

Here is the code for the doc.

 function wordCount() {
  var space = " ";
  var text = DocumentApp.getActiveDocument().getBody().getText();
  var words = text.replace(/s+/g, space).split(space);
  Logger.log(words.length);
}

Additionally I would really like a way to get the count of occurrences a single word shows on a webpage.

So in summation, my hope is that when I have a sheet that includes an "https://www.example.com" in cell A2, I would be able to run the following:

=wordCount(A2) - results in the word count for the URL
=keywordCount(A2,"keyword") - results in the count of "keyword" occurrences on "https://www.example.com"

Thanks in advance!

question from:https://stackoverflow.com/questions/66066329/webpage-word-keyword-count-google-apps-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...