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中的Descriptor描述符学习教程
Jun 02 Python
Python简单格式化时间的方法【strftime函数】
Sep 18 Python
python3之微信文章爬虫实例讲解
Jul 12 Python
python实现指定文件夹下的指定文件移动到指定位置
Sep 17 Python
对Python强大的可变参数传递机制详解
Jun 13 Python
Python一键安装全部依赖包的方法
Aug 12 Python
Tensorflow的梯度异步更新示例
Jan 23 Python
Python正则表达式学习小例子
Mar 03 Python
python实现图像拼接功能
Mar 23 Python
Python基础之元组与文件知识总结
May 19 Python
Python使用OpenCV和K-Means聚类对毕业照进行图像分割
Jun 11 Python
python的列表生成式,生成器和generator对象你了解吗
Mar 16 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脚本数据库功能详解(下)
2006/10/09 PHP
php feof用来识别文件末尾字符的方法
2010/08/01 PHP
thinkPHP的Html模板标签使用方法
2012/11/13 PHP
PHP程序员的技术成长规划
2016/03/25 PHP
MAC下通过改apache配置文件切换php多版本的方法
2017/04/26 PHP
php strftime函数获取日期时间(switch用法)
2018/05/16 PHP
JS跨域代码片段
2012/08/30 Javascript
JQuery实现带排序功能的权限选择实例
2015/05/18 Javascript
js时间戳转为日期格式的方法
2015/12/28 Javascript
React.js入门学习第一篇
2016/03/30 Javascript
jQuery自定义插件详解及实例代码
2016/12/29 Javascript
JS html时钟制作代码分享
2017/03/03 Javascript
详解vue表单验证组件 v-verify-plugin
2017/04/19 Javascript
jQuery接受后台传递的List的实例详解
2017/08/02 jQuery
three.js中3D视野的缩放实现代码
2017/11/16 Javascript
使用Vue开发一个实时性时间转换指令
2018/01/17 Javascript
VUE 使用中踩过的坑
2018/02/08 Javascript
解决使用vue.js路由后失效的问题
2018/03/17 Javascript
JS 实现缓存算法的示例(FIFO/LRU)
2018/03/20 Javascript
对类Vue的MVVM前端库的实现代码
2018/09/07 Javascript
深入理解javascript prototype的相关知识
2019/09/19 Javascript
js实现点赞效果
2020/03/16 Javascript
webpack 动态批量加载文件的实现方法
2020/03/19 Javascript
[44:09]DOTA2上海特级锦标赛A组小组赛#1 EHOME VS MVP.Phx第二局
2016/02/25 DOTA
简单使用Python自动生成文章
2014/12/25 Python
python编程开发之类型转换convert实例分析
2015/11/13 Python
python数据类型_元组、字典常用操作方法(介绍)
2017/05/30 Python
Python操作word常见方法示例【win32com与docx模块】
2018/07/17 Python
Python3.4解释器用法简单示例
2019/03/22 Python
OpenCV图像颜色反转算法详解
2019/05/13 Python
Python的in,is和id函数代码实例
2020/04/18 Python
Puma印度官网:德国运动品牌
2019/10/06 全球购物
计算机专业自荐信
2014/05/24 职场文书
股东大会通知
2015/04/24 职场文书
MySQL数据库 任意ip连接方法
2022/05/20 MySQL
oracle设置密码复杂度及设置超时退出的功能
2022/06/28 Oracle