Google Apps Script Sample Codes

IMPORTHTML(url, query, index) – Imports data from a table or list within an HTML page.

IMPORTXML(url, xpath_query) – Imports data from any of various structured data types including XML, HTML, CSV, TSV, and RSS and ATOM XML feeds.

 

FIND(search_for, text_to_search, [starting_at])

 

search_for – The string to look for within text_to_search.

 

text_to_search – The text to search for the first occurrence of search_for.

 

starting_at – [ OPTIONAL – 1 by default ] – The character within text_to_search at which to start the search.

 

SEARCH(search_for, text_to_search, [starting_at])

 

search_for – The string to look for within text_to_search.

 

text_to_search – The text to search for the first occurrence of search_for.

 

starting_at – [ OPTIONAL – 1 by default ] – The character within text_to_search at which to start the search.

 

REGEXMATCH(text, regular_expression)

 

text – The text to be tested against the regular expression.

 

regular_expression – The regular expression to test the text against. (say that (times){10} fast!).

 

encodeURIComponent(uri)

 

function scrapeGoogle() {

 

var searchResults=UrlFetchApp.fetch(“https://www.google.co.in/search?q=”+encodeURIComponent(“amarindaz youtube channel”));

var titleExp=/<h3 class=\”r\”>([\s\S]*?)<\/h3>/gi;

var titleResults=searchResults.getContentText().match(titleExp);

// Logger.log(titleResults);

for(var i in titleResults)

{

var actualTitle=titleResults[i].replace(/(^\s+)|(\s+$)/g, “”).replace(/<\/?[^>]+>/gi, “”);

Logger.log(actualTitle);

}

 

}

 

string.contains()

 

var string = “fuck@fuckers.com”;

var is_email = string.includes(“@”);

 

Syntax

string.includes(searchvalue, start)

 

Parameter Values

 

Parameter     Description

searchvalue     Required. The string to search for

start     Optional. Default 0. At which position to start the search

 

if (your_string.indexOf(‘hello’) > -1)
{
alert(“hello found inside your_string”);
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s