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中函数的用法实例教程
Sep 08 Python
Python中用函数作为返回值和实现闭包的教程
Apr 27 Python
python数据类型判断type与isinstance的区别实例解析
Oct 31 Python
python3.5 email实现发送邮件功能
May 22 Python
Python + OpenCV 实现LBP特征提取的示例代码
Jul 11 Python
在PyCharm的 Terminal(终端)切换Python版本的方法
Aug 02 Python
Flask框架钩子函数功能与用法分析
Aug 02 Python
pytorch进行上采样的种类实例
Feb 18 Python
Python 炫技操作之合并字典的七种方法
Apr 10 Python
python实现AdaBoost算法的示例
Oct 03 Python
python绕过图片滑动验证码实现爬取PTA所有题目功能 附源码
Jan 06 Python
OpenCV中resize函数插值算法的实现过程(五种)
Jun 05 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
支持数组的ADDSLASHES的php函数
2010/02/16 PHP
有关于PHP中常见数据类型的汇总分享
2014/01/06 PHP
ThinkPHP结合AjaxFileUploader实现无刷新文件上传的方法
2014/10/29 PHP
PHP实现json_decode不转义中文的方法
2017/05/20 PHP
laravel model模型处理之修改查询或修改字段时的类型格式案例
2019/10/17 PHP
JQuery验证工具类搜集整理
2013/01/16 Javascript
理解javascript中的回调函数(callback)
2014/09/02 Javascript
jQuery实现点击该行即可删除HTML表格行
2014/10/17 Javascript
javascript中this指向详解
2016/04/23 Javascript
jquery与ajax获取特殊字符实例详解
2017/01/08 Javascript
浅谈JavaScript中promise的使用
2017/01/11 Javascript
详解微信小程序入门五: wxml文件引用、模版、生命周期
2017/01/20 Javascript
ECMAScript6--解构
2017/03/30 Javascript
jQuery回调方法使用示例
2017/06/26 jQuery
JS计算输出100元钱买100只鸡问题的解决方法
2018/01/04 Javascript
angular2中Http请求原理与用法详解
2018/01/11 Javascript
微信小程序scroll-view组件实现滚动动画
2018/01/31 Javascript
详解vue挂载到dom上会发生什么
2019/01/20 Javascript
解决vue动态下拉菜单 有数据未反应的问题
2020/08/06 Javascript
Python中矩阵创建和矩阵运算方法
2018/08/04 Python
python求解数组中两个字符串的最小距离
2018/09/27 Python
python数据预处理之数据标准化的几种处理方式
2019/07/17 Python
Django模板Templates使用方法详解
2019/07/19 Python
python分别打包出32位和64位应用程序
2020/02/18 Python
使用OpenCV获取图像某点的颜色值,并设置某点的颜色
2020/06/02 Python
德国箱包网上商店:koffer24.de
2016/07/27 全球购物
兰蔻加拿大官方网站:Lancome加拿大
2016/08/05 全球购物
IGK Hair官网:喷雾、洗发水、护发素等
2020/11/03 全球购物
影视制作岗位职责
2013/12/04 职场文书
《囚绿记》教学反思
2014/03/01 职场文书
低碳生活倡议书
2014/04/14 职场文书
目标责任书范本
2014/04/16 职场文书
男性健康日的活动方案
2014/08/18 职场文书
2015年个人工作总结报告
2015/04/25 职场文书
表扬信格式模板
2015/05/05 职场文书
教你用python实现12306余票查询
2021/06/30 Python