Python批量查詢域名是否被注冊(cè)過
step1. 找一個(gè)單詞數(shù)據(jù)庫
這里有一個(gè)13萬個(gè)單詞的
http://download.csdn.net/detail/u011004567/9675906
新建個(gè)mysql數(shù)據(jù)庫words,導(dǎo)入words里面就行
step2.找個(gè)查詢接口
這里我用的是http://apistore.baidu.com/astore/serviceinfo/27586.html
step3. 執(zhí)行Python腳本
# -*- coding: utf-8 -*-
'''
域名注冊(cè)查詢
'''
__author__ = 'Jimmy'
from sqlalchemy import Column, String,Integer, create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
import requests
import json
from html.parser import HTMLParser
request_failure = []
domain_available = []
def writeToText(list,fn):
file = open(fn, 'w')
file.write(str(list))
file.close()
class bodyJSON(HTMLParser):
tag = False
def handle_starttag(self, tag, attr):
if tag == 'body':
self.tag = True
def handle_endtag(self, tag):
if tag == 'body':
self.tag = False
def handle_data(self, data):
if self.tag:
self.data = data
def getJSON(self):
return self.data
Base = declarative_base()
class Words(Base):
# 表的名字:
__tablename__ = 'words'
# 表的結(jié)構(gòu):
ID = Column(Integer(), primary_key=True)
word = Column(String(100))
exchange = Column(String(1000))
voice = Column(String(1000))
times = Column(Integer())
# 初始化數(shù)據(jù)庫連接:
engine = create_engine('mysql+mysqlconnector://root:846880@localhost:3306/words')
# 創(chuàng)建DBSession類型:
DBSession = sessionmaker(bind=engine)
# 創(chuàng)建Session:
session = DBSession()
# 創(chuàng)建Query查詢,filter是where條件,最后調(diào)用one()返回唯一行,如果調(diào)用all()則返回所有行:
words = session.query(Words).filter(Words.ID).all()
def searchInaaw8(words):
length = len(words)
print('====開始搜索...=====共%d個(gè)單詞' %length)
for i in range(0,length):
word = words[i]
url = 'http://www.aaw8.com/Api/DomainApi.aspx?domain=%s.com' % word.word
r = requests.get(url)
if r.status_code == 200:
if r.headers['Content-Type'] == 'text/html':
print('第%s個(gè)請(qǐng)求被拒絕,url = %s' % (i, url))
else:
body = bodyJSON()
body.feed(r.text)
res = json.loads(body.getJSON())
if res['StateID'] == 210:
print('第%d次,%s.com 未被注冊(cè)' % (i, word.word))
domain_available.append(word.word)
elif res['StateID'] == 0:
print('第%d次,%s.com 查詢接口出錯(cuò)' % (i, word.word))
request_failure.append(word.word)
elif res['StateID'] == 211:
pass
print('第%d次,%s.com 已經(jīng)被注冊(cè)' % (i, word.word))
elif res['StateID'] == 213:
print('第%d次,%s.com 查詢超時(shí)' % (i, word.word))
request_failure.append(word.word)
else:
print('其他錯(cuò)誤')
request_failure.append(word.word)
body.close()
else:
print('請(qǐng)求失敗')
request_failure.append(word.word)
print('查詢結(jié)束...')
print('查詢失敗:')
print(request_failure)
writeToText(request_failure,'failure.text')
print('未注冊(cè)域名:')
print(domain_available)
writeToText(request_failure,'available.text')
searchInaaw8(words)
step4:放到阿里云就可以搞事情啦

以上所述是小編給大家介紹的Python批量查詢域名是否被注冊(cè)過,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
Python使用Virtualenv進(jìn)行虛擬環(huán)境管理的詳細(xì)步驟
Virtualenv是一個(gè)Python環(huán)境管理工具,它允許開發(fā)者在不同的項(xiàng)目之間獨(dú)立創(chuàng)建和管理各自的Python環(huán)境,通過virtualenv,你可以為每個(gè)項(xiàng)目安裝特定版本的Python解釋器以及項(xiàng)目的依賴庫,本文給大家介紹了Python使用Virtualenv進(jìn)行虛擬環(huán)境管理的詳細(xì)步驟2024-09-09
Python使用matplotlib繪制余弦的散點(diǎn)圖示例
這篇文章主要介紹了Python使用matplotlib繪制余弦的散點(diǎn)圖,涉及Python操作matplotlib的基本技巧與散點(diǎn)的設(shè)置方法,需要的朋友可以參考下2018-03-03
python實(shí)現(xiàn)簡(jiǎn)單多人聊天室
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)簡(jiǎn)單多人聊天室功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12
Python Metaclass原理與實(shí)現(xiàn)過程詳細(xì)講解
MetaClass元類,本質(zhì)也是一個(gè)類,但和普通類的用法不同,它可以對(duì)類內(nèi)部的定義(包括類屬性和類方法)進(jìn)行動(dòng)態(tài)的修改??梢赃@么說,使用元類的主要目的就是為了實(shí)現(xiàn)在創(chuàng)建類時(shí),能夠動(dòng)態(tài)地改變類中定義的屬性或者方法2022-11-11
通過Python的gtts庫將文字轉(zhuǎn)為音頻的操作方法
文字轉(zhuǎn)音頻可以幫助視覺障礙者通過聽取聲音來獲取信息,也可以幫助人們方便地聽取一些長(zhǎng)篇文章或?qū)W習(xí)資料,節(jié)省閱讀時(shí)間和疲勞,這篇文章主要介紹了通過Python的gtts庫將文字轉(zhuǎn)為音頻的方法,需要的朋友可以參考下2023-05-05
在Python中,不用while和for循環(huán)遍歷列表的實(shí)例
今天小編就為大家分享一篇在Python中,不用while和for循環(huán)遍歷列表的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-02-02
Windows下的Python 3.6.1的下載與安裝圖文詳解(適合32位和64位)
這篇文章主要介紹了Windows下的Python 3.6.1的下載與安裝圖文詳解(適合32位和64位),需要的朋友可以參考下2018-02-02

