此域是否可用或已使用?在GoogleSheets应用程序脚本中

smdncfj3  于 2021-09-23  发布在  Java
关注(0)|答案(1)|浏览(457)

我在谷歌表单中有一个域名列表。我想看看godaddy或类似的网站,看看它们是否可用。
以下是应用程序脚本函数:

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";
}

它试图匹配文本“why it's great.”,只有在域名可用的情况下,该文本才会显示在结果页面上。
但是,该函数每次都返回“y”,即使对于已获取的域也是如此。
你能帮我更新这个功能吗?

l0oc07j2

l0oc07j21#

如果您只想知道域是否存在,请使用注册数据访问协议(rdap)。这并不需要一段时间来加载,因为它只返回字符串。如果域未注册,则返回404。如果您需要,也可以使用其中的详细信息,而不是付费购买高级服务。

代码:

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返回值(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"}]}]}

图纸输出:

相关问题