I am trying to make a request using Urlfetchapp
, this has been working fine for a month but now it starts giving an Error 403
message. The sample code is:
function fetchWithRetry() {
var url = 'https://www.futbin.com/25/player/55430/robin-koch'; //sample url
for (var attempt = 0; attempt < 4; attempt++) {
try {
var result = UrlFetchApp.fetch(url);
return result.getContentText(); // If successful, return the result
} catch (error) {
Logger.log("Attempt " + (attempt + 1) + " failed for URL: " + url + ". Error: " + error); // Wait before retrying
}
}
return null; // If all attempts fail, return null
}
The error looks like this:
https://www.futbin.com/25/player/55430/robin-koch. Error: Exception: Request failed for https://www.futbin.com returned code 403. Truncated server response: Just a moment...<meta htt... (use muteHttpExceptions option to examine full response)
Following this question, I tried adding headers in the request:
var url = 'https://www.futbin.com/25/player/55430/robin-koch'; //sample url
var headers = {
"authority": "www.futbin.com",
"method": "GET",
"referer": "https://www.google.com/",
"sec-ch-ua": "\"Google Chrome\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\"",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/547.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/547.36"
};
var options = {
"method": "GET",
"headers": headers,
"muteHttpExceptions": true
};
var result = UrlFetchApp.fetch(url,options);
But it did not work out either. Can we use a proxy in the request header as mentioned in this answer? I am trying to get the following values from the webpage as a result, I would appreciate any workaround to resolve this: