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实现对PPT文件进行截图操作的方法
Apr 28 Python
python写入xml文件的方法
May 08 Python
python统计文本文件内单词数量的方法
May 30 Python
Python 类的继承实例详解
Mar 25 Python
Python算术运算符实例详解
May 31 Python
Python中int()函数的用法浅析
Oct 17 Python
python调用虹软2.0第三版的具体使用
Feb 22 Python
python实现维吉尼亚加密法
Mar 20 Python
对python中assert、isinstance的用法详解
Nov 27 Python
python实现对变位词的判断方法
Apr 05 Python
python3实现将json对象存入Redis以及数据的导入导出
Jul 16 Python
python和Appium的移动端多设备自动化测试框架
Apr 26 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实现的功能是显示8条基色色带
2006/10/09 PHP
模拟OICQ的实现思路和核心程序(二)
2006/10/09 PHP
PHP curl 获取响应的状态码的方法
2014/01/13 PHP
ThinkPHP文件缓存类代码分享
2015/04/22 PHP
PHP中key和current,next的联合运用实例分析
2016/03/29 PHP
PHP CURL与java http使用方法详解
2018/01/26 PHP
PHP7 echo和print语句实例用法
2019/02/15 PHP
原生js实现半透明遮罩层效果具体代码
2013/06/06 Javascript
js中substring和substr的定义和用法
2014/05/05 Javascript
基于Flowplayer打造一款免费的WEB视频播放器附源码
2015/09/06 Javascript
微信小程序 wx.request(接口调用方式)详解及实例
2016/11/23 Javascript
JavaScript中各数制转换全面总结
2017/08/21 Javascript
angular json对象push到数组中的方法
2018/02/27 Javascript
Vue中的transition封装组件的实现方法
2019/08/13 Javascript
VSCode搭建Vue项目的方法
2020/04/30 Javascript
Python实现提取谷歌音乐搜索结果的方法
2015/07/10 Python
详解在Python程序中解析并修改XML内容的方法
2015/11/16 Python
使用Python3 编写简单信用卡管理程序
2016/12/21 Python
使用Python对Csv文件操作实例代码
2017/05/12 Python
python 实现返回一个列表中出现次数最多的元素方法
2019/06/11 Python
python开启debug模式的方法
2019/06/27 Python
Flask框架学习笔记之消息提示与异常处理操作详解
2019/08/15 Python
关于Python turtle库使用时坐标的确定方法
2020/03/19 Python
使用python爬取抖音app视频的实例代码
2020/12/01 Python
纯css3实现鼠标经过图片显示描述的动画效果
2014/09/01 HTML / CSS
HTML5 canvas实现移动端上传头像拖拽裁剪效果
2016/03/14 HTML / CSS
override和overload的区别
2016/03/09 面试题
会计大学生职业生涯规划书范文
2014/01/13 职场文书
电焊工工作岗位职责
2014/02/06 职场文书
同学会主持词
2014/03/18 职场文书
领导干部查摆“四风”问题自我剖析材料思想汇报
2014/10/05 职场文书
通知的写法
2015/04/23 职场文书
2015年酒店销售部工作总结
2015/07/24 职场文书
教学工作总结范文5篇
2019/08/19 职场文书
python装饰器代码解析
2022/03/23 Python
Redis如何实现验证码发送 以及限制每日发送次数
2022/04/18 Redis