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之复习if语句
Oct 02 Python
linux下python抓屏实现方法
May 22 Python
Python实现获取域名所用服务器的真实IP
Oct 25 Python
Python设计模式编程中解释器模式的简单程序示例分享
Mar 02 Python
如何在python中使用selenium的示例
Dec 26 Python
python pandas dataframe 行列选择,切片操作方法
Apr 10 Python
python2与python3共存问题的解决方法
Sep 18 Python
解决Python中pandas读取*.csv文件出现编码问题
Jul 12 Python
自定义Django默认的sitemap站点地图样式
Mar 04 Python
Keras预训练的ImageNet模型实现分类操作
Jul 07 Python
python中二分查找法的实现方法
Dec 06 Python
Python Django搭建文件下载服务器的实现
May 10 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中通过Ajax如何实现异步文件上传的代码实例
2011/05/07 PHP
Drupal7 form表单二次开发要点与实例
2014/03/02 PHP
PHP7正式版测试,性能惊艳!
2015/12/08 PHP
php实现的表单验证类完整示例
2019/08/13 PHP
在一个js文件里远程调用jquery.js会在ie8下的一个奇怪问题
2010/11/28 Javascript
使用jquery动态加载javascript以减少服务器压力
2012/10/29 Javascript
jQuery实现密保互斥问题解决方案
2013/08/16 Javascript
JS 两个字符串时间的天数差计算
2013/08/25 Javascript
javascript实现自动填写表单实例简析
2015/12/02 Javascript
javascript图片切换综合实例(循环切换、顺序切换)
2016/01/13 Javascript
全面解析JavaScript中apply和call以及bind(推荐)
2016/06/15 Javascript
JQuery EasyUI学习教程之datagrid 添加、修改、删除操作
2016/07/09 Javascript
javascript数组常用方法汇总
2016/09/10 Javascript
通过修改360抢票的刷新频率和突破8车次限制实现方法
2017/01/04 Javascript
JS简单验证上传文件类型的方法
2017/04/17 Javascript
原生JS实现隐藏显示图片 JS实现点击切换图片效果
2021/01/27 Javascript
结合Vue控制字符和字节的显示个数的示例
2018/05/17 Javascript
在Layui 的表格模板中,实现layer父页面和子页面传值交互的方法
2019/09/10 Javascript
python3序列化与反序列化用法实例
2015/05/26 Python
Windows下的Python 3.6.1的下载与安装图文详解(适合32位和64位)
2018/02/21 Python
Python格式化字符串f-string概览(小结)
2019/06/18 Python
python实现简单俄罗斯方块
2020/03/13 Python
详解CSS3选择器:nth-child和:nth-of-type之间的差异
2017/09/18 HTML / CSS
HTML5地理定位实例
2014/10/15 HTML / CSS
Ray-Ban雷朋美国官网:全球领先的太阳眼镜品牌
2016/07/20 全球购物
四方通行旅游网:台湾订房、出国旅游
2017/09/20 全球购物
eharmony澳大利亚:网上约会服务
2020/02/29 全球购物
五年级音乐教学反思
2014/02/06 职场文书
巡警年度自我鉴定
2014/02/21 职场文书
学校搬迁方案
2014/06/15 职场文书
普通党员个人剖析材料
2014/10/08 职场文书
写给父母的感谢信
2015/01/22 职场文书
2015年父亲节活动总结
2015/02/12 职场文书
卡特教练观后感
2015/06/08 职场文书
导游词之长城八达岭
2019/09/24 职场文书
python使用matplotlib绘制图片时x轴的刻度处理
2021/08/30 Python