作者ppppppppp (凹嗚嗚)
看板Google
標題[詢問] 請問google apps script的UrlFetchApp
時間Thu Mar 9 12:51:43 2023
想請問一下
我要在google apps script做一個函數
讓使用者可以在google sheet輸入關鍵字和一個網站的網址
計算出在用google搜尋該關鍵字時
該網站會排在第幾名
我的google apps script程式碼:
function getGoogleRank(keyword, url) {
var searchUrl = '
https://www.google.com/search?q=' + encodeURIComponent(keywor
d) + '&num=100';
var response = UrlFetchApp.fetch(searchUrl);
var content = response.getContentText();
var regex = new RegExp(url, 'i');
var rank = content.search(regex);
if (rank == -1) {
return '未排名';
} else {
return rank + 1;
}
}
出現以下的錯誤訊息:
Exception: Request failed for
https://www.google.com returned code 429. Truncate
d server response: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN
">
<html>
<head><meta http-equiv="content-type" content="text/html; charset=utf-8"><me...
(use muteHttpExceptions option to examine full response)
好像是太過頻繁跟google請求
該如何解決這個問題呢
謝謝
----
Sent from
BePTT on my Samsung SM-G9980
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.236.30.87 (臺灣)
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Google/M.1678337505.A.949.html
※ 編輯: ppppppppp (36.236.30.87 臺灣), 03/09/2023 12:52:27
1F:→ mayfirst: stackoverflow.com/questions/66429810/ 03/16 13:55
2F:→ mayfirst: 這裡有一樣的問題,大概是Google搜尋會鎖UrlFetch的 03/16 13:58
3F:→ mayfirst: request,所以可能要另外用API去解決 03/16 13:59