python爬站长之家写一个信息搜集器
前言:
不知道写什么好,绕来绕去还是写回爬虫这一块。
之前的都爬了一遍。这次爬点好用一点的网站。
0x01:
自行备好requests模块
目标站:http://tool.chinaz.com/
0x2:
代码:
import optparse
import requests
import re
import sys
from bs4 import BeautifulSoup
def main():
usage="[-z Subdomain mining]" \
"[-p Side of the station inquiries]" \
"[-x http status query]"
parser=optparse.OptionParser(usage)
parser.add_option('-z',dest="Subdomain",help="Subdomain mining")
parser.add_option('-p',dest='Side',help='Side of the station inquiries')
parser.add_option('-x',dest='http',help='http status query')
(options,args)=parser.parse_args()
if options.Subdomain:
subdomain=options.Subdomain
Subdomain(subdomain)
elif options.Side:
side=options.Side
Side(side)
elif options.http:
http=options.http
Http(http)
else:
parser.print_help()
sys.exit()
def Subdomain(subdomain):
print('-----------Subdomains quickly tap-----------')
url="http://m.tool.chinaz.com/subdomain/?domain={}".format(subdomain)
header={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}
r=requests.get(url,headers=header).content
g = re.finditer('<td>\D[a-zA-Z0-9][-a-zA-Z0-9]{0,62}\D(\.[a-zA-Z0-9]\D[-a-zA-Z0-9]{0,62})+\.?</td>', str(r))
for x in g:
lik="".join(str(x))
opg=BeautifulSoup(lik,'html.parser')
for link in opg.find_all('td'):
lops=link.get_text()
print(lops)
def Side(side):
print('--------Side of the station inquiries--------')
url="http://m.tool.chinaz.com/same/?s={}".format(side)
header={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}
r=requests.get(url,headers=header).content
g=r.decode('utf-8')
ksd=re.finditer('<a href=.*?>[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?</a>',str(g))
for l in ksd:
ops="".join(str(l))
pods=BeautifulSoup(ops,'html.parser')
for xsd in pods.find_all('a'):
sde=re.findall('[a-zA-z]+://[^\s]*',str(xsd))
low="".join(sde)
print(low)
def Http(http):
print('--------Http status query--------')
url="http://{}".format(http)
header={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}
r=requests.get(url,headers=header)
b=r.headers
for sdw in b:
print(sdw,':',b[sdw])
if __name__ == '__main__':
main()
运行截图:
-h 帮助
-z 子域名挖掘
-p 旁站查询
-x http状态查询
-z 截图
-p 截图
-x 截图
距离上学还有5天。啊啊啊啊啊啊啊啊啊啊啊
python爬站长之家写一个信息搜集器的更多相关文章
- 使用python爬取MedSci上的期刊信息
使用python爬取medsci上的期刊信息,通过设定条件,然后获取相应的期刊的的影响因子排名,期刊名称,英文全称和影响因子.主要过程如下: 首先,通过分析网站http://www.medsci.cn ...
- python爬取当当网的书籍信息并保存到csv文件
python爬取当当网的书籍信息并保存到csv文件 依赖的库: requests #用来获取页面内容 BeautifulSoup #opython3不能安装BeautifulSoup,但可以安装Bea ...
- python 拼写检查代码(怎样写一个拼写检查器)
原文:http://norvig.com/spell-correct.html 翻译:http://blog.youxu.info/spell-correct.html 怎样写一个拼写检查器 Pete ...
- Python+Flask+Gunicorn 项目实战(一) 从零开始,写一个Markdown解析器 —— 初体验
(一)前言 在开始学习之前,你需要确保你对Python, JavaScript, HTML, Markdown语法有非常基础的了解.项目的源码你可以在 https://github.com/zhu-y ...
- 用 EPWA 写一个 图片播放器 PicturePlayer
用 EPWA 写一个 图片播放器 PicturePlayer . 有关 EPWA,见 <我发起并创立了一个 EPWA 的 开源项目> https://www.cnblogs.com ...
- Python的scrapy之爬取链家网房价信息并保存到本地
因为有在北京租房的打算,于是上网浏览了一下链家网站的房价,想将他们爬取下来,并保存到本地. 先看链家网的源码..房价信息 都保存在 ul 下的li 里面 爬虫结构: 其中封装了一个数据库处理模 ...
- python写一个信息收集四大件的脚本
0x0前言: 带来一首小歌: 之前看了小迪老师讲的课,仔细做了些笔记 然后打算将其写成一个脚本. 0x01准备: requests模块 socket模块 optparser模块 time模块 0x02 ...
- Python爬取链家二手房源信息
爬取链家网站二手房房源信息,第一次做,仅供参考,要用scrapy. import scrapy,pypinyin,requests import bs4 from ..items import L ...
- 零基础爬虫----python爬取豆瓣电影top250的信息(转)
今天利用xpath写了一个小爬虫,比较适合一些爬虫新手来学习.话不多说,开始今天的正题,我会利用一个案例来介绍下xpath如何对网页进行解析的,以及如何对信息进行提取的. python环境:pytho ...
随机推荐
- Vuex初识
vuex是vue中单向数据流的一个状态管理模式,它可以集中存储管理应用中所有组件的状态,并且有一套相应的规则可以去预测数据的变化.类似与此的还有react中的redux,dva等状态管理模式. 一般我 ...
- 01 整合IDEA+Maven+SSM框架的高并发的商品秒杀项目之业务分析与DAO层
作者:nnngu 项目源代码:https://github.com/nnngu/nguSeckill 这是一个整合IDEA+Maven+SSM框架的高并发的商品秒杀项目.我们将分为以下几篇文章来进行详 ...
- Flexbox学习总结
flex语法 采用Flex布局的元素,称为Flex容器(flex container),简称"容器".它的所有子元素自动成为容器成员,称为Flex项目(flex item),简称& ...
- Mac 下 搭建 svn 服务器
Mac自带了svn服务端和客户端,所以只需要简单配置一下就可以使用. 1.创建svn repository svnadmin create /Users/gaohf/svn/repository 2. ...
- Android + Eclipse + PhoneGap 环境配置
用了3天的时间,终于把环境搭建完毕,郁闷了N天,终于完成了.这里我只是讲述我安装的过程,仅供大家参考. 环境搭建首先要去下载一些安装包: (下载前注意一下,电脑是32位还是64位的请注意选择安装包) ...
- python 与redis
一.redis安装 源码安装: 1.wget http://download.redis.io/redis-stable.tar.gz 2.yum install gcc 3.tar zx ...
- redux学习日志:关于异步action
当我们在执行某个动作的时候,会直接dispatch(action),此时state会立即更新,但是如果这个动作是个异步的呢,我们要等结果出来了才能知道要更新什么样的state(比如ajax请求),那就 ...
- cpuimage 开源之
前年学习opengl做的一个小东西. 原本计划将gpuimage 的算法一个一个转写成cpu版本 c,c++ 版本. gpuimage 项目参考: https://github.com/BradLar ...
- FORTH运算符
body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...
- CentOS6.x机器安装Azure CLI2.0【2】
安装Azure CLI 2.0的前提是:机器中必须有 Python 2.7.x 或 Python 3.x.如果机器中没有其中任何一个Python版本,请及时安装 1.准备一台CentOS 6.9的机器 ...