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通过poll实现异步IO的方法
Jun 04 Python
python读取word文档,插入mysql数据库的示例代码
Nov 07 Python
python实现多层感知器MLP(基于双月数据集)
Jan 18 Python
Linux上使用Python统计每天的键盘输入次数
Apr 17 Python
详解【python】str与json类型转换
Apr 29 Python
python 实现的发送邮件模板【普通邮件、带附件、带图片邮件】
Jul 06 Python
python opencv捕获摄像头并显示内容的实现
Jul 11 Python
Django logging配置及使用详解
Jul 23 Python
python从zip中删除指定后缀文件(推荐)
Dec 05 Python
python输入一个水仙花数(三位数) 输出百位十位个位实例
May 03 Python
Node.js 和 Python之间该选择哪个?
Aug 05 Python
python用海龟绘图写贪吃蛇游戏
Jun 18 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 字符过滤类,用于过滤各类用户输入的数据
2009/05/27 PHP
php 备份数据库代码(生成word,excel,json,xml,sql)
2013/06/23 PHP
PHP实现支持加盐的图片加密解密
2016/09/09 PHP
PHP实现的猴王算法(猴子选大王)示例
2018/04/30 PHP
js中top、clientTop、scrollTop、offsetTop的区别 文字详细说明版
2011/01/08 Javascript
解决ExtJS在chrome或火狐中正常显示在ie中不显示的浏览器兼容问题
2013/01/11 Javascript
JQUERY 获取IFrame中对象及获取其父窗口中对象示例
2013/08/19 Javascript
jQuery实现DIV层淡入淡出拖动特效的方法
2015/02/13 Javascript
jQuery实现图片渐入渐出切换展示效果
2015/08/15 Javascript
通过js获取上传的图片信息(临时保存路径,名称,大小)然后通过ajax传递给后端的方法
2015/10/01 Javascript
JavaScript制作颜色反转小游戏
2016/09/25 Javascript
详解Angular 4.x NgTemplateOutlet
2017/05/24 Javascript
javascript计算对象长度的方法
2017/10/25 Javascript
js前端导出Excel的方法
2017/11/01 Javascript
AngularJS与后端php的数据交互方法
2018/08/13 Javascript
vue使用v-for实现hover点击效果
2018/09/29 Javascript
vue视频播放插件vue-video-player的具体使用方法
2019/11/08 Javascript
python获取豆瓣电影简介代码分享
2014/01/16 Python
Python random模块常用方法
2014/11/03 Python
深入解读Python解析XML的几种方式
2016/02/16 Python
Python实现抓取网页生成Excel文件的方法示例
2017/08/05 Python
Python中几种属性访问的区别与用法详解
2018/10/10 Python
解决在pycharm中显示额外的 figure 窗口问题
2019/01/15 Python
浅谈Python程序的错误:变量未定义
2020/06/02 Python
利用PyTorch实现VGG16教程
2020/06/24 Python
资金主管岗位职责范本
2014/03/04 职场文书
捐助倡议书范文
2014/04/15 职场文书
施工工地安全标语
2014/06/07 职场文书
超市周年庆活动方案
2014/08/16 职场文书
合同和协议有什么区别?
2014/10/08 职场文书
竞聘报告优秀范文
2014/11/06 职场文书
小学优秀教师事迹材料
2014/12/16 职场文书
2015年度酒店客房部工作总结
2015/05/25 职场文书
网络舆情信息简报
2015/07/21 职场文书
GoLang中生成UUID唯一标识的实现
2021/05/08 Golang
Python中的协程(Coroutine)操作模块(greenlet、gevent)
2022/05/30 Python