Python批量查询域名是否被注册过


Posted in Python onJune 21, 2017

step1. 找一个单词数据库

这里有一个13万个单词的

http://download.csdn.net/detail/u011004567/9675906

新建个mysql数据库words,导入words里面就行

step2.找个查询接口

这里我用的是http://apistore.baidu.com/astore/serviceinfo/27586.html

step3. 执行Python脚本

# -*- 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批量查询域名是否被注册过

以上所述是小编给大家介绍的Python批量查询域名是否被注册过,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!

Python 相关文章推荐
Python的print用法示例
Feb 11 Python
利用Python爬取微博数据生成词云图片实例代码
Aug 31 Python
ubuntu中配置pyqt4环境教程
Dec 27 Python
python的Tqdm模块的使用
Jan 10 Python
python实现微信远程控制电脑
Feb 22 Python
Python 使用PIL中的resize进行缩放的实例讲解
Aug 03 Python
numpy基础教程之np.linalg
Feb 12 Python
python读取与处理netcdf数据方式
Feb 14 Python
pycharm设置python文件模板信息过程图解
Mar 10 Python
django实现后台显示媒体文件
Apr 07 Python
python中使用.py配置文件的方法详解
Nov 23 Python
python文件名批量重命名脚本实例代码
Apr 22 Python
Python图片裁剪实例代码(如头像裁剪)
Jun 21 #Python
Python编程实战之Oracle数据库操作示例
Jun 21 #Python
Python获取SQLite查询结果表列名的方法
Jun 21 #Python
基于hashlib模块--加密(详解)
Jun 21 #Python
详谈Python基础之内置函数和递归
Jun 21 #Python
浅谈python内置变量-reversed(seq)
Jun 21 #Python
python 简单的绘图工具turtle使用详解
Jun 21 #Python
You might like
PHP 创建标签云函数代码
2010/05/26 PHP
PHP的autoload机制的实现解析
2012/09/15 PHP
php实现设计模式中的单例模式详解
2014/10/11 PHP
php获取微信共享收货地址的方法
2017/12/21 PHP
用js实现判断当前网址的来路如果不是指定的来路就跳转到指定页面
2011/05/02 Javascript
基于jquery的回到页面顶部按钮
2011/06/27 Javascript
asp.net网站开发中用jquery实现滚动浏览器滚动条加载数据(类似于腾讯微博)
2012/03/14 Javascript
在JavaScript里嵌入大量字符串常量的实现方法
2013/07/07 Javascript
JQuery插件开发示例代码
2013/11/06 Javascript
利用进制转换压缩数字函数分享
2014/01/02 Javascript
jquery结合CSS使用validate实现漂亮的验证
2015/01/29 Javascript
JavaScript中诡异的delete操作符
2015/03/12 Javascript
使用ngView配合AngularJS应用实现动画效果的方法
2015/06/19 Javascript
JavaScript焦点事件、鼠标事件和滚轮事件使用详解
2016/01/15 Javascript
JavaScript实现使用Canvas绘制图形的基本教程
2016/10/27 Javascript
在 Angular2 中实现自定义校验指令(确认密码)的方法
2017/01/23 Javascript
AngularJS入门教程二:在路由中传递参数的方法分析
2017/05/27 Javascript
nodejs动态创建二维码的方法
2017/08/12 NodeJs
layui 监听表格复选框选中值的方法
2018/08/15 Javascript
基于vue-cli、elementUI的Vue超简单入门小例子(推荐)
2019/04/17 Javascript
Vue export import 导入导出的多种方式与区别介绍
2020/02/12 Javascript
JS实现进度条动态加载特效
2020/03/25 Javascript
Python使用ftplib实现简易FTP客户端的方法
2015/06/03 Python
python 计算数组中每个数字出现多少次--“Bucket”桶的思想
2017/12/19 Python
浅谈配置OpenCV3 + Python3的简易方法(macOS)
2018/04/02 Python
python查看数据类型的方法
2019/10/12 Python
python3.x 生成3维随机数组实例
2019/11/28 Python
pandas apply使用多列计算生成新的列实现示例
2021/02/24 Python
WoolOvers爱尔兰:羊绒、羊毛和棉针织品
2017/01/04 全球购物
澳大利亚第一旅行车和房车配件店:Caravan RV Camping
2020/12/26 全球购物
关于赌博的检讨书
2014/01/08 职场文书
综合素质自我评价怎么写
2014/09/14 职场文书
2015年助理工程师工作总结
2015/04/03 职场文书
钱学森观后感
2015/06/04 职场文书
2016年心理学教育培训学习心得体会
2016/01/12 职场文书
POST提交数据常见的四种方式
2022/01/18 HTML / CSS