pythonXXX云所有厂商
2015-08-25 13:29
459 查看
第一步:
#!usr/bin/env python#coding=utf-8#url列表import urllib,urllib2,renumber=raw_input('enter a number:\n')link='http://www.wooyun.org/corps/page/'newf=open('xh.txt','w')for s in range(int(number)):f=str(link+str(s+1))newf.writelines(f+'\n')if number==0:passelse:print fnewf.close()door=open('xh.txt','r')print door.readlines()door.close()第二步:#!usr/bin/env python#coding=utf-8#完整爬虫import string,urllib2,urllib,resend_headers = {'Host':'www.wooyun.org','User-Agent':'Mozilla/5.0 (Windows NT 6.2; rv:16.0) Gecko/20100101 Firefox/16.0','Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Connection':'keep-alive'}newf=open('result.txt','w')def jx():door=open('xh.txt','r')t=door.readlines()for m in t:url=m#print urlurl=mreq = urllib2.Request(url,headers=send_headers)r=urllib2.urlopen(req)html=r.read()unicodepage=html.decode('utf-8')#print unicodepagemyitems=re.findall('_blank">.*?</a>',unicodepage,re.S)items=[]for items in myitems:items=items.replace('_blank">','')items=items.replace('</a>','')items=items.replace('<img src="/images/sae_bottom_logo.png" title="Powered by Sina App Engine"></a-->','')items=items.replace('</span>','')items=items.replace('<span class="other fright">','')items=items.replace('<a href="/impression">行业观点</a>','')items=items.replace('乌云招聘','')items=items.replace('知识库','')items=items.replace('<a href="/impression">行业观点','')items=items.replace('http://','')items=items.replace('/','')items=items.replace(',','\n')print itemsnewf.writelines(items+'\n')door.close()newf.close()jx()收工
相关文章推荐
- python find file
- (转)python 计算代码行数以及相关知识点
- Python并发编程
- 【Python】[进程和线程]多进程,多线程,ThreadLocal,进程VS.线程,分布式进程
- Python中time和datetime模块对时间的操作
- Python 中 datetime时间模块学习
- Python 获取文件信息
- python类实例方法,类方法,类静态方法
- 使用Python的Bottle框架写一个简单的服务接口的示例
- 6.python 分支与循环
- python偏函数
- 学习的知识点记录
- python函数式编程内建函数filter,map,reduce函数
- Python 命令行解析工具 Argparse介绍
- gevent 写的bench URL 的小工具
- 【转】使用virtualenv在ubuntu上搭建python 3开发环境
- 机器学习算法与Python实践之(五)k均值聚类(k-means)
- python中做层次聚类,使用scipy.cluster.hierarchy.fclusterdata方法
- 5.python 算术操作符逻辑操作符
- Python中self的含义