最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin6浏览0评论

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论