Python 爬虫插件
#coding:utf-8
import sys,urllib2,re,Queue
sys.path.append("..")
from lib.Http_Class import Http_Class
from BeautifulSoup import BeautifulSoup
####################################
#
# Spider 爬虫模块
#
####################################
class Spider_module:
def setW3AScan(self,w3ascan):
self.w3ascan=w3ascan
self.result_list={}
self.q_list=Queue.Queue()
self.tmp_list=Queue.Queue()
def start(self,aa):
url="http://lucifr.com/"
print "[*] 爬虫目标:"+url
self.result_list.update({url:0})
try:
while True:
# 判断爬虫是否有爬过
for url in self.result_list:
if self.result_list[url]==0:
self.q_list.put(url)
self.result_list[url]=1
# 判断任务队列是否为空,如果是则直接退出
# 否则处理任务
if self.q_list.empty():
print "[*] 结束爬虫任务."
break
else:
for tmp in range(self.q_list.qsize()):
spider_url=self.q_list.get()
obj=Http_Class()
try:
html=obj._do("get",spider_url)
except:
self.w3ascan.log_create("url: %s Field! " % spider_url,"Spider_module")
print "url: %s Field! " % spider_url
continue
soup=BeautifulSoup(html)
links=soup.findAll('a')
for link in links:
_url=link.get('href').encode('utf-8')
if re.match('^(javascript|:;|#|mailto)',_url) or _url is None or re.match('.(jpg|png|bmp|mp3|wma|wmv|gz|zip|rar|iso|pdf|txt|db)$',_url):
continue
if re.match('^(http|https)',_url):
if not re.match('^'+url,_url):
continue
else:
if self.result_list.has_key(url):
continue
else:
rst=_url.encode('utf-8')
print "[*][!] 发现新连接: "+rst
self.result_list.update({rst:0})
else:
if self.result_list.has_key(url+_url):
continue
else:
rst=url+_url
print "[*][!] 发现新连接: "+rst.encode('utf-8')
self.result_list.update({rst.encode('utf-8'):0})
except Exception,error:
print "[*] 发生异常情况,捕获并写入日志。"
self.w3ascan.log_create("Url: %s get Url Error! Source: %s" % (url,error),"Spider_module")
def save(self):
print "[*]保存爬虫结果"
def getPluginClass():
return Spider_module
if __name__=="__main__":
t=Spider_module()
t.start("aaa")
Python 爬虫插件的更多相关文章
- Python 爬虫6——Scrapy的安装和使用
前面我们简述了使用Python自带的urllib和urllib2库完成的一下爬取网页数据的操作,但其实能完成的功能都很简单,假如要进行复制的数据匹配和高效的操作,可以引入第三方的框架,例如Scrapy ...
- python爬虫抓网页的总结
python爬虫抓网页的总结 更多 python 爬虫 学用python也有3个多月了,用得最多的还是各类爬虫脚本:写过抓代理本机验证的脚本,写过在discuz论坛中自动登录自动发贴的脚本,写过自 ...
- 使用notepad++学习python爬虫,print网页中文乱码问题
今天学习使用python爬虫的时候发现爬到的网页中文会乱码,一直网上搜索解决办法,一个一个试验过去,发现还是乱码,然后我就开始使用其它方法测试,用python自带的编辑器打开是正常的,发现是notep ...
- Python爬虫小白---(二)爬虫基础--Selenium PhantomJS
一.前言 前段时间尝试爬取了网易云音乐的歌曲,这次打算爬取QQ音乐的歌曲信息.网易云音乐歌曲列表是通过iframe展示的,可以借助Selenium获取到iframe的页面元素, 而QQ音乐采用的是 ...
- Python爬虫:用BeautifulSoup进行NBA数据爬取
爬虫主要就是要过滤掉网页中没用的信息.抓取网页中实用的信息 一般的爬虫架构为: 在python爬虫之前先要对网页的结构知识有一定的了解.如网页的标签,网页的语言等知识,推荐去W3School: W3s ...
- Python 爬虫——抖音App视频抓包
APP抓包 前面我们了解了一些关于 Python 爬虫的知识,不过都是基于 PC 端浏览器网页中的内容进行爬取.现在手机 App 用的越来越多,而且很多也没有网页端,比如抖音就没有网页版,那么上面的视 ...
- Python爬虫实战一之爬取QQ音乐
一.前言 前段时间尝试爬取了网易云音乐的歌曲,这次打算爬取QQ音乐的歌曲信息.网易云音乐歌曲列表是通过iframe展示的,可以借助Selenium获取到iframe的页面元素, 而QQ音乐采用的是 ...
- Python爬虫与数据分析之爬虫技能:urlib库、xpath选择器、正则表达式
专栏目录: Python爬虫与数据分析之python教学视频.python源码分享,python Python爬虫与数据分析之基础教程:Python的语法.字典.元组.列表 Python爬虫与数据分析 ...
- python爬虫工具集合
python爬虫工具集合 大家一起来整理吧!强烈建议PR.这是初稿,总是有很多问题,而且考虑不全面,希望大家支持! 源文件 主要针对python3 常用库 urllib Urllib是python提供 ...
随机推荐
- Python学习笔记:time模块的使用
在使用python的过程中,很多情况下会使用到日期时间,在Python的自建函数中,包含time模块,用来处理与日期时间相关的功能. 1.time.time() time():不能传参数 用来获取时间 ...
- HTTP Status 500 ? Internal Server Error
getWriter()和getOutputStream()不能同时调用 HTTP Status 500 ? Internal Server Error Type Exception Report Me ...
- CMake下,某些选项的后调整
编译安卓NDK库时,发现在R15的NDK编译出来的库,总是带了-g选项,导致附带调试,文件过大. 搜索一番后,结论是NDK的文件中有问题: https://github.com/android/ndk ...
- java:LeakFilling(Springmvc)
1.后台可以同时多个对象接收前端页面的值:(如图两个都打印了) 2.参数绑定的注解,通过该注解可以解决参数名称与controller中形参名称不一致的问题: @RequestParam(name=&q ...
- pandas的.columns和.index
可以通过.columns和.index着两个属性返回数据集的列索引和行索引 设data是pandas的一个DataFram类型的数据集. 则data.index返回一个index类型的行索引列表,da ...
- 【VS开发】动态添加的ActiveX控件如何响应事件
http://blog.csdn.net/xiaoqiqixiao/article/details/574542 今天在csdn上看到一朋友问如何响应动态添加的控件的事件,搜索资料,发现对于一般的应用 ...
- 【VS开发】win7下让程序默认以管理员身份运行
在win7中用自己写的程序读取MBR时,突然提示无法对磁盘进行操作,而在xp下并没有这个问题:最后点右键以管理员身份运行才可以正常运行.于是想办法让程序在双击启动时默认以管理员身份运行.具体方法: 1 ...
- 微信小程序--catchtap&bindtap
转自:https://www.cnblogs.com/heron-yu/p/7244481.html 转自:http://blog.csdn.net/xiaochun365/article/detai ...
- [Python3] 031 常用模块 shutil & zipfile
目录 shutil 1. shutil.copy() 2. shutil.copy2() 3. shutil.copyfile() 4. shutil.move() 5. 归档 5.1 shutil. ...
- Cause: org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org ...