我正在檢查是否可以使用 gstatic 從網站上抓取圖示。下面將獲取網站 Favicon:
https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://yahoo.com&size=64
我知道 URL 引數可能不適合一般用途,而只是檢查是否有人知道這可能記錄在哪里?
更新:我剛剛開始在 Google App Script 上構建一個應用程式。我需要列出網站名稱及其網站圖示和元資料,如網站描述等。目前唯一的方法是閱讀網頁并使用 beautifulSoup 決議頁面,然后找到網站圖示。我遇到了上面的鏈接,它將直接給我網站圖示!但我想更好地理解它并嘗試找到有關 gstatic 的 URL 引數的更多資訊。我也對從 Google App Script 抓取網站的替代方法持開放態度......
謝謝
uj5u.com熱心網友回復:
我相信你的目標如下。
- 您想從網站上檢索網站圖示。
- 您想使用以下示例 URL。
https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://yahoo.com&size=64
- 從
I need to list website names along with their favicons and metadata like site description, etc.中,您想使用 Google Apps 腳本檢索網站的圖示、標題和描述。
示例腳本 1:
當使用你的 URL 時https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://yahoo.com&size=64,下面的示例腳本怎么樣?請將以下腳本復制并粘貼到 Google Apps 腳本的腳本編輯器中。并且,samoke1在腳本編輯器中運行。
function sample1() {
const uri = 'https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://yahoo.com&size=64';
const blob = UrlFetchApp.fetch(encodeURI(uri)).getBlob();
DriveApp.createFile(blob);
}
- 運行此腳本時,將檢索網站圖示并將其作為檔案保存到 Google Drive 的根檔案夾中。
- 當我看到 URL 時,似乎將 favicon 檢索為影像資料。
示例腳本 2:
當檢索網站的圖示、標題和描述時,下面的示例腳本怎么樣?
function sample2() {
const uri = 'https://yahoo.com'; // Please set the URL.
const obj = { title: "", description: "", faviconUrl: "" };
const res = UrlFetchApp.fetch(encodeURI(uri));
const html = res.getContentText();
const title = html.match(/<title>(. ?)<\/title>/i);
if (title || title.length > 1) {
obj.title = title[1];
}
const description = html.match(/<meta. name\="description". >/i);
if (description) {
const d = description[0].match(/content\="(. )"/i);
if (d && d.length > 1) {
obj.description = d[1];
}
}
const faviconUrl = html.match(/rel="icon". ?href\="(. ?)"/i);
if (faviconUrl && faviconUrl.length > 1) {
obj.faviconUrl = faviconUrl[1];
}
console.log(obj);
}
運行此腳本時,您可以在日志中看到以下值。
{ "title":"Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports & Videos", "description":"Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!", "faviconUrl":"https://s.yimg.com/cv/apiv2/default/icons/favicon_y19_32x32_custom.svg" }
參考:
- 獲取(網址)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/475636.html
上一篇:正則運算式中遺漏了某些數字問題
