cheeriogs
Cheerio/ jQuery for Google Apps Script
AI Summary
cheerio for Google Apps Script
Provides Cheerio in GAS for jQuery-like HTML parsing.
Target Users
Beginner to intermediate GAS developers who want to parse and manipulate HTML for web scraping or content processing.
Problems Solved
Cannot directly use Node.js Cheerio in GAS, solving jQuery-like HTML selector parsing issues.
Script ID
- In GAS Editor: Click "Libraries +" → Paste into "Script ID" field → Click "Look up"
- "cheeriogs" will appear in the search results
- Select the latest version (highest number) from "Version" dropdown
- Click "Add"
Tags
Main Features
1
Cheerio 1.0.0
Updates Cheerio to 1.0.0 with webpack bundling for latest features and performance in GAS.
2
Easy Addition
Add via GAS editor with Script ID 1ReeQ6WO8kKNxoaA_O0XEQ589cIrRvEBA9qcWpNqdOP17i47u6N9M5Xh0 as 'Cheerio'.
3
cheerio.load API
Use Cheerio.load(content) to get $ instance with .text(), selectors, same as cheerio API.
Examples
Main Functions
| Function | Description |
|---|---|
| Cheerio.load | Loads HTML to Cheerio $ instance |
Examples
Wikipedia Main Page Right Content
/**
* Wikipediaメインページ右側取得
* ・URLコンテンツ取得: UrlFetchApp.fetch(url).getContentText()
* ・Cheerioロード: Cheerio.load(content)
* ・要素テキスト抽出: $("#mp-right").text()
*/
function getWikipediaRightContent() {
const url = 'https://en.wikipedia.org';
const content = UrlFetchApp.fetch(url).getContentText();
const $ = Cheerio.load(content);
Logger.log($('#mp-right').text());
}Wikipedia First Paragraph
/**
* Wikipedia最初の段落取得
* ・URLコンテンツ取得: UrlFetchApp.fetch(url).getContentText()
* ・Cheerioロード: Cheerio.load(content)
* ・最初の要素テキスト: $("p").first().text()
*/
function getWikipediaFirstParagraph() {
const url = 'https://en.wikipedia.org';
const content = UrlFetchApp.fetch(url).getContentText();
const $ = Cheerio.load(content);
Logger.log($('p').first().text());
}Modify HtmlService Output
/**
* HtmlService出力操作
* ・HTMLコンテンツ取得: HtmlService.createHtmlOutputFromFile("index").getContent()
* ・Cheerioロード・操作: Cheerio.load(html); $("#main").append("...")
* ・HTML再構築出力: Utilities.formatString("<html>%s</html>", $("html").html())
*/
function modifyHtmlServiceOutput() {
const html = HtmlService.createHtmlOutputFromFile("index").getContent();
const $ = Cheerio.load(html);
$("#main").append("<p>Cheeriosse!!1</p>");
return HtmlService.createHtmlOutput(
Utilities.formatString("<html>%s</html>", $("html").html())
);
}