javascript - 该域名是否可用或已被占用?在 Google 表格应用脚本中

标签 javascript google-apps-script web-scraping google-sheets

我在 Google 表格中有一个域列表。我想通过查看 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”,即使对于已占用的域也是如此。

你能帮我更新这个功能吗?

最佳答案

如果您只想知道域是否存在,请使用注册数据访问协议(protocol) (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","<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4b2a293e382e2824263b272a22253f380b262a3920262425223f243965282426" rel="noreferrer noopener nofollow">[email protected]</a>"]]]}]}],"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"}]}]}

工作表输出:

output

关于javascript - 该域名是否可用或已被占用?在 Google 表格应用脚本中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68318697/

相关文章:

excel - 如何从 btn 类网络抓取中提取属性详细信息

python - Scrapy:连接被拒绝

javascript - 使用 node.js api 递归地监视目录

javascript - Bootstrap 选择下拉菜单只有图标

google-apps-script - 如何使用 ContentService 和 doPost 创建 REST API

python - 使用 BeautifulSoup 从网页中提取某些内容时遇到问题

javascript - 如何使用 Javascript 或 jQuery 在 TinyMCE 编辑器中获取 HTML 元素节点值

javascript - CORS Cookie 未在跨域上设置,使用获取,设置凭据 : 'include' and origins have been set

google-apps-script - 如何在 Google 表格中使用复选框和脚本隐藏和取消隐藏列?

javascript - Google Apps 脚本从日期对象返回错误的分钟