批量查询5个字成语首字母组成的.com域名

.com域名无疑是最受欢迎的后缀,1至4个字母的组合已全部被抢注。好奇心驱使下,写了Python程序批量查询5个字成语首字母组成的.com域名的注册情况。

步骤1:抓取5个字的成语

详情见博文《Python爬取成语:从3字到12字》,结果已分享在GitHub,见这里,共558个(实际上应该不止)。

步骤2:翻译成拼音

将5个字成语(如:严师出高徒)转换成拼音,提取每个汉字的首字母,组成.com域名(yscgt.com)。我使用的是xpinyin模块,用以下命令安装该模块:

sudo pip install xpinyin

核心源代码如下:

#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from xpinyin import Pinyin #https://github.com/lxneng/xpinyin #not support for python3

def hanzi_to_pinyin(in_filename, out_filename):
    p = Pinyin()
    chinese_idioms_pinyin = list()
    f_in = open(in_filename, 'r')
    f_out = open(out_filename, 'w')

    for idiom in f_in.readlines() :
        #translate hanzi to pinyin, with the python module
        t = (idiom,
             p.get_initials(unicode(idiom), u'').lower(),
             p.get_pinyin(unicode(idiom), '', show_tone_marks=False),
             p.get_pinyin(unicode(idiom), ' ', show_tone_marks=True))

        t = (item.rstrip('\n') for item in t) #remove '\n'

        chinese_idioms_pinyin.append(t)


    for t in chinese_idioms_pinyin :
        s = '\t'.join(t)
        f_out.write(s + '\n')

    f_in.close()
    f_out.close()

得到的结果,取部分如下:

恶虎不食子    ehbsz    ehubushizi    è hǔ bù shí zǐ 
赶鸭子上架    gyzsj    ganyazishangjia    gǎn yā zǐ shàng jià 
坐山观虎斗    zsghd    zuoshanguanhudou    zuò shān guān hǔ dǒu 
兄弟阋于墙    xdxyq    xiongdixiyuqiang    xiōng dì xì yú qiáng 
顾头不顾尾    gtbgw    gutoubuguwei    gù tóu bù gù wěi 
好汉惜好汉    hhxhh    haohanxihaohan    hǎo hàn xī hǎo hàn 
郁郁不得志    yybdz    yuyubudezhi    yù yù bù dé zhì 
治标不治本    zbbzb    zhibiaobuzhiben    zhì biāo bù zhì běn 
摸不着头脑    mbztn    mobuzhaotounao    mō bù zháo tóu nǎo 

步骤3:批量查询是否被抢注

用Pyhton whois模块,主要源代码如下:

#!/usr/bin/env python

import whois  #pip install python-whois
import string
import itertools
   
def find_unregistered_names(self, filename, index):
    fp = open(filename, 'r')
    
    for line in fp.readlines() :
        str_list = line.split()
        for suffix in self.domain_suffixes :
            url = str_list[index] + '.' + str(suffix)
            str_list[index] = url
            
            try :
                w = whois.whois(url)
            except (whois.parser.PywhoisError):
                self.unregistered_names.append(str_list)
            except (UnicodeError) :  #fp.readlines()[100:102]
                continue

    fp.close()

得到的结果,共258个,还是蛮多的,取部分如下:

老牛拉破车    lnlpc.com
养虎自遗患    yhzyh.com
一鼻孔出气    ybkcq.com
攫金不见人    jjbjr.com
老大徒伤悲    ldtsb.com
打鸭子上架    dyzsj.com
破鼓乱人捶    pglrc.com
久旱逢甘雨    jhfgy.com
驽马恋栈豆    nmlzd.com
大事不糊涂    dsbht.com
心服口不服    xfkbf.com
不吃烟火食    bcyhs.com
天公不做美    tgbzm.com
恶人先告状    erxgz.com
礼轻人意重    lqryz.com
独木不成林    dmbcl.com
不以辞害志    bychz.com
天不转地转    tbzdz.com
难于上青天    nysqt.com
赞赏

微信赞赏支付宝赞赏

发表回复

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