Skip to content
This repository has been archived by the owner on Apr 24, 2022. It is now read-only.

gas-commons/HtmlParser

Repository files navigation

clasp JavaScript Style Guide

HtmlParser

HTML Parser for Googe Apps Script

Usage

Add library

project key: 1gMNYu6-SlYdKbfFMSXZz718quQVgll-qKhNobIaJwMVYL_9EgZ9GQlmp

Use in your script

Example:

var html = UrlFetchApp.fetch('http://en.wikipedia.org/wiki/Document_Object_Model').getContentText()
var doc = XmlService.parse(html)
var rootElement = doc.getRootElement()

var parser = HtmlParser.of(rootElement)
var element = parser.getElementById('firstHeading')

API

API is inspired by Document.

getElementById(id)

var element = parser.getElementById('firstHeading')

getElementsByClassName(className)

var elements = parser.getElementsByClassName('firstHeading')

getElementsByTagName(tagName)

var elements = parser.getElementsByTagName('h1')

Reference