step1. 找一個單詞數據庫
這里有一個13萬個單詞的
http://download.csdn.net/detail/u011004567/9675906
新建個mysql數據庫words,導入words里面就行
step2.找個查詢接口
這里我用的是http://apistore.baidu.com/astore/serviceinfo/27586.html
step3. 執行Python腳本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# -*- coding: utf-8 -*- ''' 域名注冊查詢 ''' __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' # 表的結構: ID = Column(Integer(), primary_key = True ) word = Column(String( 100 )) exchange = Column(String( 1000 )) voice = Column(String( 1000 )) times = Column(Integer()) # 初始化數據庫連接: engine = create_engine( 'mysql+mysqlconnector://root:846880@localhost:3306/words' ) # 創建DBSession類型: DBSession = sessionmaker(bind = engine) # 創建Session: session = DBSession() # 創建Query查詢,filter是where條件,最后調用one()返回唯一行,如果調用all()則返回所有行: words = session.query(Words). filter (Words. ID ). all () def searchInaaw8(words): length = len (words) print ( '====開始搜索...=====共%d個單詞' % 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個請求被拒絕,url = %s' % (i, url)) else : body = bodyJSON() body.feed(r.text) res = json.loads(body.getJSON()) if res[ 'StateID' ] = = 210 : print ( '第%d次,%s.com 未被注冊' % (i, word.word)) domain_available.append(word.word) elif res[ 'StateID' ] = = 0 : print ( '第%d次,%s.com 查詢接口出錯' % (i, word.word)) request_failure.append(word.word) elif res[ 'StateID' ] = = 211 : pass print ( '第%d次,%s.com 已經被注冊' % (i, word.word)) elif res[ 'StateID' ] = = 213 : print ( '第%d次,%s.com 查詢超時' % (i, word.word)) request_failure.append(word.word) else : print ( '其他錯誤' ) request_failure.append(word.word) body.close() else : print ( '請求失敗' ) request_failure.append(word.word) print ( '查詢結束...' ) print ( '查詢失敗:' ) print (request_failure) writeToText(request_failure, 'failure.text' ) print ( '未注冊域名:' ) print (domain_available) writeToText(request_failure, 'available.text' ) searchInaaw8(words) |
step4:放到阿里云就可以搞事情啦
以上所述是小編給大家介紹的Python批量查詢域名是否被注冊過,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
原文鏈接:http://www.jianshu.com/p/2325e0240da0