"web scraping with UrlFetchApp" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "web scraping with UrlFetchApp" answered properly. Developers are finding an appropriate answer about web scraping with UrlFetchApp related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like web scraping with UrlFetchApp. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on web scraping with UrlFetchApp.
web scraping with UrlFetchApp
/**
* Scrape URL, return whatever you choose with jquery-style selectors. Dependency: cheeriogs, see https://github.com/fgborges/cheeriogs
*
* @param {url} valid start-url
* @return result (array values)
*
* @customfunction
*/
function scraper(url) {
var result = [];
var title, ogurl, ogtitle, ogimage, ogdescription, description, h1, robots, canonical;
var options = {
'muteHttpExceptions': true,
'followRedirects': false,
};
try {
// trim url to prevent (rare) errors
url.toString().trim();
var r = UrlFetchApp.fetch(url, options);
var c = r.getResponseCode();
// check for meta refresh if 200 ok
if (c == 200) {
var html = r.getContentText();
var $ = Cheerio.load(html); // make sure this lib is added to your project!
// meta robots
if ($('meta[name="robots"]').attr('content')) {
robots = $('meta[name="robots"]').attr('content').trim();
}
// canonical
if ($("link[rel='canonical']").attr("href")) {
canonical = $("link[rel='canonical']").attr("href");
}
// meta title
if ($('title')) {
title = $('title').text().trim();
}
// meta description
if ($('meta[name=description]').attr("content")) {
description = $('meta[name=description]').attr("content").trim();
}
// h1
if ($('h1')) {
h1 = $('h1').text().trim();
}
// open graph url
if ($('meta[property="og:url"]').attr('content')) {
ogurl = $('meta[property="og:url"]').attr('content').trim();
}
// open graph title
if ($('meta[property="og:title"]').attr('content')) {
ogtitle = $('meta[property="og:title"]').attr('content').trim();
}
// open graph image
if ($('meta[property="og:image"]').attr('content')) {
ogimage = $('meta[property="og:image"]').attr('content');
}
// open graph description
if ($('meta[property="og:description"]').attr('content')) {
ogdescription = $('meta[property="og:description"]').attr('content').trim();
}
}
result.push([c, canonical, robots, title, description, h1, ogurl, ogtitle, ogimage, ogdescription]);
} catch (error) {
result.push(error.toString());
} finally {
return result;
}
}
Source: eikhart.com
All those coders who are working on the Whatever based application and are stuck on web scraping with UrlFetchApp can get a collection of related answers to their query. Programmers need to enter their query on web scraping with UrlFetchApp related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about web scraping with UrlFetchApp for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of web scraping with UrlFetchApp while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "web scraping with UrlFetchApp". Visit this developer's friendly online web community, CodeProZone, and get your queries like web scraping with UrlFetchApp resolved professionally and stay updated to the latest Whatever updates.