Is this domain available or taken? In Google Sheets apps script

Viewed 441

I have a list of domains in Google Sheets. I'd like to find out if they are available or not, by looking at Godaddy or similar site.

Here is the apps script function:

function domainavail(url)
{
   url = "https://www.godaddy.com/domainsearch/find?checkAvail=1&segment=repeat&domainToCheck="+url;
   var options = {
     'muteHttpExceptions': true,
     'followRedirects': false
   };
   var response = UrlFetchApp.fetch(url, options);
   var html     = response.getContentText();

   if ( html.match(/Why it's great./) )
     return "Y";
   return "N";
}

It is trying to match the text "Why it's great." which should only show up on the result page if the domain is available.

However, the function is returning "Y" every time, even for domains that are taken.

Can you help me update this function?

1 Answers

If you just want to know if the domain is existing or not, use Registration Data Access Protocol (RDAP). This doesn't take a while to load as it only returns string. And returns 404 if the domain isn't registered. There are also details there that you might be able to use instead of paying for premium services if you want them.

Code:

function domainavail(url) {
  var options = {
    'muteHttpExceptions': true,
    'followRedirects': false
  };
  var html = UrlFetchApp.fetch('https://rdap.verisign.com/com/v1/domain/' + url, options).getContentText();

  if(html.length == 0)
    return "Y";
  return "N";
}

RDAP return value (youtube.com):

{"objectClassName":"domain","handle":"142504053_DOMAIN_COM-VRSN","ldhName":"YOUTUBE.COM","links":[{"value":"https:\/\/rdap.verisign.com\/com\/v1\/domain\/YOUTUBE.COM","rel":"self","href":"https:\/\/rdap.verisign.com\/com\/v1\/domain\/YOUTUBE.COM","type":"application\/rdap+json"},{"value":"https:\/\/rdap.markmonitor.com\/rdap\/domain\/YOUTUBE.COM","rel":"related","href":"https:\/\/rdap.markmonitor.com\/rdap\/domain\/YOUTUBE.COM","type":"application\/rdap+json"}],"status":["client delete prohibited","client transfer prohibited","client update prohibited","server delete prohibited","server transfer prohibited","server update prohibited"],"entities":[{"objectClassName":"entity","handle":"292","roles":["registrar"],"publicIds":[{"type":"IANA Registrar ID","identifier":"292"}],"vcardArray":["vcard",[["version",{},"text","4.0"],["fn",{},"text","MarkMonitor Inc."]]],"entities":[{"objectClassName":"entity","roles":["abuse"],"vcardArray":["vcard",[["version",{},"text","4.0"],["fn",{},"text",""],["tel",{"type":"voice"},"uri","tel:+1.2083895740"],["email",{},"text","abusecomplaints@markmonitor.com"]]]}]}],"events":[{"eventAction":"registration","eventDate":"2005-02-15T05:13:12Z"},{"eventAction":"expiration","eventDate":"2022-02-15T05:13:12Z"},{"eventAction":"last update of RDAP database","eventDate":"2021-07-09T09:23:30Z"}],"secureDNS":{"delegationSigned":false},"nameservers":[{"objectClassName":"nameserver","ldhName":"NS1.GOOGLE.COM"},{"objectClassName":"nameserver","ldhName":"NS2.GOOGLE.COM"},{"objectClassName":"nameserver","ldhName":"NS3.GOOGLE.COM"},{"objectClassName":"nameserver","ldhName":"NS4.GOOGLE.COM"}],"rdapConformance":["rdap_level_0","icann_rdap_technical_implementation_guide_0","icann_rdap_response_profile_0"],"notices":[{"title":"Terms of Use","description":["Service subject to Terms of Use."],"links":[{"href":"https:\/\/www.verisign.com\/domain-names\/registration-data-access-protocol\/terms-service\/index.xhtml","type":"text\/html"}]},{"title":"Status Codes","description":["For more information on domain status codes, please visit https:\/\/icann.org\/epp"],"links":[{"href":"https:\/\/icann.org\/epp","type":"text\/html"}]},{"title":"RDDS Inaccuracy Complaint Form","description":["URL of the ICANN RDDS Inaccuracy Complaint Form: https:\/\/icann.org\/wicf"],"links":[{"href":"https:\/\/icann.org\/wicf","type":"text\/html"}]}]}

Sheet Output:

output

Related