1、Python 将域名取出并进行计数排序
用生成器是否好点:
from urllib import parse
from collections import Counter
def parse_domain():
with open("c:\\a.txt",'rt') as f:
for l in f.readlines():
yield parse.urlparse(l)[1]
for k,v in Counter(parse_domain()).most_common():
print(v,k)
2、Python实现从url中提取域名的几种方法
u
3、python3.5的怎么通过域名知道网站所有者
一、域名查询
万网提供了域名查询接口,接口采用HTTP协议:
接口URL:
接口参数:area_domain,接口参数值为标准域名,例:52bong.com
调用举例:
返回:<?xml version="1.0" encoding="gb2312"?>
<property>
<returncode>200</returncode>
<key>52bong.com</key>
<original>211 : Domain exists</original>
</property>
返回结果说明:200 返回码,200表示返回成功
52bong.com 表示当前查询的域名
211 : Domain exists 返回结果的原始信息,主要有以下几种
original=210 : Domain name is available 表示域名可以注册
original=211 : Domain exists 表示域名已经注册
original=212 : Domain name is invalid 表示查询的域名无效
original=213 : Time out 查询超时
Python实现
1.1 查询已经被注册的域名>>> import urllib2
[quote]>> req=urllib2.urlopen('h')
>>> print (req.read().decode())
返回结果:不可用,已经被注册
1.2 查询没有被注册的域名>>> req2=urllib2.urlopen('')
>>> print (req2.read().decode())
返回结果:可用,未被注册
1.3 查询不加后缀的域名>>> req3=urllib2.urlopen('')
>>> print (req3.read().decode())
返回结果:超时
二、whois查询
由于没有找到像域名查询接口那样好的API,这里直接抓取站长之家的whois查询页面)>>> whois = urllib2.urlopen('')
>>> print (whois.read().decode())
在返回的结果中有这样一段html代码,这段信息就是查询的whois信息
4、有没有可以像百度爬虫一样的python程序。把中国所有域名都采集保存下来。希望有大哥可以给我一份,
你表达的不是很清楚!
采集域名有啥用?
你是说采集每个正常运行的域名下的网站内容吗?
但我得告诉,这个程序很多,搜索引擎很多人都写过!但你得有硬件成本才行啊!中国啊,多少个网站!你如果你用单台电脑采集,估计你的从现在开始到你老死还采集不完!百度的服务器数量已经数以万计,懂吗?
如果你只采集几个特定的网站,还可以搞的定啊
5、python如何从网页中提取列表中字典中的域名
假设那个字典叫dict:
if dict.has_key( line[0] ):
print dict[ line[0] ]
和列表一样,用[ ]即可
6、如何使用多线程python扫描二级子域名
日站没什么好办法了往往也会想到其二级域名,于是写了一个比较简陋的扫描二级域名的程序
速度一般般,不过如果线程开多了还是可以的
源程序(subdomain.py):
#! /usr/bin/env python
#coding=utf-8
import threading , Queue, optparse, os
import pycurl, StringIO, msvcrt, socket
queue = Queue.Queue()
class ScanThread(threading.Thread):
def __init__(self, queue):
threading.Thread.__init__(self)
self.queue = queue
def run(self):
while 1:
p = self.queue.get()
if p is None:
break
try:
sub_domain = p+'.'+domain
crl = pycurl.Curl()
crl.fa = StringIO.StringIO()
crl.setopt(pycurl.URL,sub_domain)
crl.setopt(pycurl.VERBOSE,0)
crl.setopt(pycurl.FOLLOWLOCATION,1)
crl.setopt(pycurl.MAXREDIRS,5)
crl.setopt(pycurl.CONNECTTIMEOUT, 60)
crl.setopt(pycurl.TIMEOUT, 300)
crl.setopt(crl.WRITEFUNCTION,crl.fa.write)
try:
crl.perform()
ip=socket.gethostbyname(sub_domain)
print sub_domain, ip
content = sub_domain+' '+ip+'\n'
self.writefile(wfile, 'a+', content)
except:
pass
except:
print "error"
self.writefile('F:/py/Domain/log.txt', 'a+', p+'\n')
queue.task_done()
def writefile(self, path, type, content):
f = open(path, type)
f.write(content)
f.close
class ThreadGetKey(threading.Thread):
def run(self):
while 1:
try:
chr = msvcrt.getch()
if chr == 'q':
print "stopped by your action ( q )"
os._exit(1)
else:
continue
except:
os._exit(1)
# now starting...
def main():
parser = optparse.OptionParser('Usages: %prog -d <domain> -r <read> -w <write> -t <thread(s)>')
parser.add_option('-d',dest='domain',type='string',help='the url to query')
parser.add_option('-r',dest='read',type='string',help='the dic file to read default=F:/py/Domain/dic.txt', default='F:/py/Domain/dic.txt')
parser.add_option('-w',dest='write',type='string',help='save the reasults to the catalogue \
default=F:/py/Domain/results.txt', default='F:/py/Domain/results.txt')
parser.add_option('-t',dest='threads',type='int',help='set the thread(s) default=10',default=10)
(options,args) = parser.parse_args()
if options.domain == None:
使用方法:
python subdomain.py -d baidu.com -r dic.txt -w results.txt -t 50
主要影响速度的是这一块代码:
try:
crl.perform()
ip=socket.gethostbyname(sub_domain)
print sub_domain, ip
content = sub_domain+' '+ip+'\n'
self.writefile(wfile, 'a+', content)
except:
pass
主要是一开始理解错了,以为二级域名不存在和某个网页不存在一样会返回404代码,于是想到用返回码来判断。
结果后来程序一直出错,才发现当二级域名不存在的时候返回的是“未找到服务器”,根本不存在返回码,于是只能使用一个try来调试错误,主要速度也就被这里影响了。当然线程开多了也是可以看到刷屏效果的~~
7、python 获取域名是泛域名还是实际域名
使用urllib.parse.urlparse(url).hostname获取域名,通过socket.gethostbyname(域名)获取IP地址,再通过socket.gethostbyaddr(ip地址就可以得到)真实的hostname了。 代码示例 python3.x: import urllib.parseimport socketurl = '你要获取的网...
8、python 怎么将"<url testabc.good.com> This is a test url"中的域名替换为"abc.good.com"
import re
a = '<url testabc.good.com> This is a test url'
print re.sub("(?<=url )test",'',a)
9、如何用python优雅地扫描可用域名
用python-2.7.3\python是对的,但是你的hello.py放在那里?你需要先用“cd 目录名”转换当前目录到存放hello.py的地方,然后执行python-2.7.3\python hello.py。
10、python怎么判断某个域名是顶级域名还是二级域名
比如:baidu.com 这是百度的顶级域名
.baidu.com 这是二级域名
www.baidu.com这也是二级域名
..baidu.com 这是三级域名
*.baidu.com 这是泛域名
习惯上这样区分,一般不称谓一级域名。个别人说指的一级域名就是顶级域名。