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中文问题解决方法(总结了多位前人经验,初学者必看)
Mar 13 Python
python实现扫描日志关键字的示例
Apr 28 Python
Python运维开发之psutil库的使用详解
Oct 18 Python
Linux下Pycharm、Anaconda环境配置及使用踩坑
Dec 19 Python
pandas DataFrame 交集并集补集的实现
Jun 24 Python
解决python flask中config配置管理的问题
Jul 26 Python
python实现音乐播放器 python实现花框音乐盒子
Feb 25 Python
在python image 中实现安装中文字体
May 16 Python
解决keras,val_categorical_accuracy:,0.0000e+00问题
Jul 02 Python
python中关于数据类型的学习笔记
Jul 19 Python
使用pandas实现筛选出指定列值所对应的行
Dec 13 Python
Python使用psutil库对系统数据进行采集监控的方法
Aug 23 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
为什么《星际争霸》是测试人工智能的理想战场
2019/12/03 星际争霸
PHP PDO函数库详解
2010/04/27 PHP
sphinx增量索引的一个问题
2011/06/14 PHP
PHP cdata 处理(详细介绍)
2013/07/05 PHP
深入解析PHP的Yii框架中的event事件机制
2016/03/17 PHP
PHP基于单例模式编写PDO类的方法
2016/09/13 PHP
PHP进程通信基础之信号
2017/02/19 PHP
百度Popup.js弹出框进化版 拖拽小框架发布 兼容IE6/7/8,Firefox,Chrome
2010/04/13 Javascript
javascript游戏开发之《三国志曹操传》零部件开发(四)用地图块拼成大地图
2013/01/23 Javascript
用Move.js配合创建CSS3动画的入门指引
2015/07/22 Javascript
js实现瀑布流的三种方式比较
2020/06/28 Javascript
webpack多入口多出口的实现方法
2018/08/17 Javascript
JS校验与最终登陆界面功能完整示例
2020/01/13 Javascript
vue任意关系组件通信与跨组件监听状态vue-communication
2020/10/18 Javascript
使用vue编写h5公众号跳转小程序的实现代码
2020/11/27 Vue.js
python实现RSA加密(解密)算法
2016/02/17 Python
django中send_mail功能实现详解
2018/02/06 Python
Python判断是否json是否包含一个key的方法
2018/12/31 Python
使用CodeMirror实现Python3在线编辑器的示例代码
2019/01/14 Python
基于python 微信小程序之获取已存在模板消息列表
2019/08/05 Python
python中删除某个元素的方法解析
2019/11/05 Python
Scrapy 配置动态代理IP的实现
2020/09/28 Python
pycharm使用技巧之自动调整代码格式总结
2020/11/04 Python
Web前端页面跳转并取到值
2017/04/24 HTML / CSS
美国汽车性能部件和赛车零件网站:Vivid Racing
2018/03/27 全球购物
REN Clean Skincare官网:英国本土有机护肤品牌
2019/02/23 全球购物
最新的大学生找工作自我评价
2013/09/29 职场文书
大学自主招生自荐信范文
2014/02/26 职场文书
商业企业管理专业求职信
2014/07/10 职场文书
教师四风问题整改措施
2014/09/25 职场文书
2015年党员干部承诺书
2015/01/21 职场文书
摘录式读书笔记
2015/07/01 职场文书
心得体会格式及范文
2016/01/25 职场文书
会议开幕致辞怎么写
2016/03/03 职场文书
Redis高级数据类型Hyperloglog、Bitmap的使用
2021/05/24 Redis
vue3种table表格选项个数的控制方法
2022/04/14 Vue.js