google apps script - DNS error when using URLfetchapp for a URL with "=" stringURL with potential Redirect iss

UPDATEI discovered that the entire domain "; appears to give DNS error when using urlfetchapp, no

UPDATE

I discovered that the entire domain "; appears to give DNS error when using urlfetchapp, not just this specific page. Perhaps this is some sort of protection against scraping?


I've been trying to use the Google App script UrlFetchApp command to extract an excel file from a uRL link on a website (which you can normally click on to download to your PC). This is the URL:

=.xlsx

However, it always give me the following error:

Error
Exception: DNS error: =.xlsx

(without using encodeURIComponent)

or

Error
Exception: DNS error: .xlsx

(when using encodeURIComponent)

I am not sure why I am having this error with this particular URL. Normally it's not a problem. Here is the code I used to extract the blob in Google App Script:

    function apiFetch() {
    
    // URL part
    var encodeComponent = "v2022_1741001884711RmViLTIwMjVQLnhsc3g=.xlsx"
    var baseurl = "/"
    var url = baseurl + encodeURIComponent(encodeComponent)

    // Fetch contents from API endpoint.
    const apiResponse = UrlFetchApp.fetch(url).getBlob();
  
    }

Note that I have no idea how this URL gets the excel file or if there is some sort of automatic redirect to some place the UrlFetchApp doesn't like (like a private server) which is causing the DNS problem for GAS but not for a browser. Some people in the community have suggested that this may be the case, but there is no way of telling.

In any case, I tried the following to deal with redirect and it still gives me the same DNS error:

const apiResponse = UrlFetchApp.fetch(url, {'followRedirects': false, 'muteHttpExceptions': false});

And in my effort to figure out where the redirect URL is also failed as I still get the same DNS error:

var followedPost = UrlFetchApp.fetch(url, {'followRedirects': false, 'muteHttpExceptions': false});
Logger.log(followedPost.getHeaders()['Location']);

I even tried the code on this website: / and I still get the same DNS error

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744871447a4598284.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信