Skip to main content

Code snippet functions

從 published google docs/ google slides 取得 title (不使用 google APIs)

const title = fetch(`${publishedUrl}`)
//解析成網頁的HTML文本
.then((response) => response.text())
.then((text) => {
let parser = new DOMParser();
const htmlDoc = parser.parseFromString(text, "text/html");
const title = htmlDoc.title;
return title;
})
.catch((error) => {
console.log(error);
});

補充: DOMParser 是一個 JavaScript API,用於解析 XML 或 HTML 文本並將其轉換為 DOM(Document Object Model)物件,以此在 JavaScript 中操作這些文檔