查询域名状态(用python解析网页返回的XML数据,gd转utf8)

一段Python代码测试域名是否可以注册。用到了panda.www.net.cn提供的一个接口,返回的是一个XML数据。

例如
在浏览器里输入

http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=xiaoxia.org

返回值是

<?xml version="1.0" encoding="gb2312"?>
<property>
<returncode>200</returncode>
<key>xiaoxia.org</key>
<original>211 : Domain name is not available</original>
</property>

使用xml.etree.ElementTree来解析上面的XML数据。
因为它不支持gb2312,所以需要在解析前,转换成utf-8格式的。
然后判断original的值来得知域名是否可用。

import urllib, xml.etree.ElementTree

def check_domain(domain):
    data = urllib.urlopen("http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=" + domain).read()
    data = unicode(data.replace("gb2312", "utf-8"), encoding="gb2312").encode("utf-8")
    e = xml.etree.ElementTree.fromstring(data)
    if e.find("returncode").text == "200":
        code = e.find("original").text[:3]
        if code == "210": return True
    return False

def main():
    while True:
        name = raw_input("input a domain: ")
        domain = name + ".com"
        print "checking domain", domain, ":", str(check_domain(domain))
        domain = name + ".net"
        print "checking domain", domain, ":", str(check_domain(domain))
        domain = name + ".org"
        print "checking domain", domain, ":", str(check_domain(domain))
if __name__ == "__main__":
    main()

写了个for循环,获取了从0x00.com到0xff.com的域名状态。
下面这些都是可以注册的,喜欢的人就注册吧!

checking 0x14.com : True
checking 0x1c.com : True
checking 0x2d.com : True
checking 0x39.com : True
checking 0x3c.com : True
checking 0x3d.com : True
checking 0x48.com : True
checking 0x4c.com : True
checking 0x4e.com : True
checking 0x4f.com : True
checking 0x56.com : True
checking 0x57.com : True
checking 0x5a.com : True
checking 0x5b.com : True
checking 0x6b.com : True
checking 0x71.com : True
checking 0x75.com : True
checking 0x7a.com : True
checking 0x7c.com : True
checking 0x7d.com : True
checking 0x81.com : True
checking 0x84.com : True
checking 0x85.com : True
checking 0x87.com : True
checking 0x8a.com : True
checking 0x8b.com : True
checking 0x8d.com : True
checking 0x8e.com : True
checking 0x94.com : True
checking 0x9a.com : True
checking 0x9b.com : True
checking 0x9c.com : True
checking 0x9d.com : True
checking 0x9e.com : True
checking 0xa1.com : True
checking 0xa2.com : True
checking 0xa4.com : True
checking 0xa6.com : True
checking 0xa7.com : True
checking 0xa8.com : True
checking 0xa9.com : True
checking 0xac.com : True
checking 0xae.com : True
checking 0xb1.com : True
checking 0xb2.com : True
checking 0xb3.com : True
checking 0xb4.com : True
checking 0xb5.com : True
checking 0xb6.com : True
checking 0xb7.com : True
checking 0xb9.com : True
checking 0xba.com : True
checking 0xc1.com : True
checking 0xc2.com : True
checking 0xc3.com : True
checking 0xc4.com : True
checking 0xc5.com : True
checking 0xc6.com : True
checking 0xc7.com : True
checking 0xc8.com : True
checking 0xc9.com : True
checking 0xca.com : True
checking 0xcd.com : True
checking 0xd1.com : True
checking 0xd2.com : True
checking 0xd3.com : True
checking 0xd4.com : True
checking 0xd5.com : True
checking 0xd6.com : True
checking 0xd7.com : True
checking 0xd8.com : True
checking 0xd9.com : True
checking 0xe1.com : True
checking 0xe2.com : True
checking 0xe4.com : True
checking 0xe5.com : True
checking 0xe6.com : True
checking 0xe8.com : True
checking 0xe9.com : True
checking 0xec.com : True
checking 0xee.com : True
checking 0xef.com : True
checking 0xf1.com : True
checking 0xf6.com : True
checking 0xf7.com : True
checking 0xf8.com : True
checking 0xf9.com : True
checking 0xfb.com : True

查询域名状态(用python解析网页返回的XML数据,gd转utf8)》有7个想法

  1. John

    不知道和直接查询 Whois服务器比速度怎样。之前我也做了个,参考了老外的代码,查询了10万个数字域名,能注册的里面全都是带4的。

    回复
    1. Xiaoxia 文章作者

      嗯,这个访问http的方法的确比较慢。如果网络好,再结合多线程,速度还是可以的!

      回复
    1. Xiaoxia 文章作者

      我看Linux下的whois的源代码,好像指定了一大堆的whois servers,不知道是连到什么地方的。

      回复
      1. wlll

        貌似可以查询*.whois-servers.net
        Ex:com –>>com.whois-servers.net
        net –>>net.whois-servers.net
        me –>>me.whois-servers.net

        回复

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据