`

scapy安装and简介

 
阅读更多

在《开源python网络爬虫框架Scrapy介绍》一文中介绍了Scrapy这个Python爬虫框架。Scrapy是一个快速,高层次的屏幕抓取和web抓取框架,用于抓取web站点并从页面中提取结构化的数据。Scrapy用途广泛,可以用于数据挖掘、监测和自动化测试。Scrapy吸引人的地方在于它是一个框架,任何人都可以根据需求方便的修改。它也提供了多种类型爬虫的基类,如BaseSpider、sitemap爬虫等,最新版本又提供了web2.0爬虫的支持。

下面介绍Scrapy在windows下的安装:

首先下载windows版:Scrapy-0.15.0.2842.win32.exe,直接安装。

安装之后不能直接运行scrapy提供的test,会提示错误,因为scrapy基于其他一些python库,需要把这些库都安装才行。

Twisted:Twisted Matrix 是一种用来进行网络服务和应用程序编程的纯 Python 框架,虽然 Twisted Matrix 中有大量松散耦合的模块化组件,但该框架的中心概念还是非阻塞异步服务器这一思想。Twisted的安装也非常简单,在这里直接下载windows平台下的相应版本即可:http://pypi.python.org/packages/2.7/T/Twisted/

zope.interface:在这里下载http://pypi.python.org/pypi/zope.interface/3.8.0#downloads。zope.interface没有提供windows平台下的exe版,只提供了windows平台下的egg包。

ez_setup:下载http://pypi.python.org/pypi/ez_setup,安装。将egg文件放置在{python安装目录}\Scripts目录下。

打开CMD并切换至scripts目录,easy_install zope.interface-3.8.0-py2.6-win32.egg安装。

w3lib:zope.interface问题解决之后还会提示缺少w3lib,下载http://pypi.python.org/pypi/w3lib后安装即可

libxml2:使用scrapy的html解析功能时,会提示你缺少libxml2,所以我们先把这个也装上,地址http://xmlsoft.org/sources/win32/python/,下载相应的版本即可。

至此就可以使用Scrapy玩spider了,大家可以根据文档写一个简单的爬虫试试,实际上使用scrapy做一个简易的爬虫甚至只需要几行代码就可以了,以后有空再详细说说使用方法,本文不做更多描述。

 

所谓网络爬虫,就是一个在网上到处或定向抓取数据的程序,当然,这种说法不够专业,更专业的描述就是,抓取特定网站网页的HTML数据。不过由于一个网站的网页很多,而我们又不可能事先知道所有网页的URL地址,所以,如何保证我们抓取到了网站的所有HTML页面就是一个有待考究的问题了。

一般的方法是,定义一个入口页面,然后一般一个页面会有其他页面的URL,于是从当前页面获取到这些URL加入到爬虫的抓取队列中,然后进入到新新页面后再递归的进行上述的操作,其实说来就跟深度遍历或广度遍历一样。

上面介绍的只是爬虫的一些概念而非搜索引擎,实际上搜索引擎的话其系统是相当复杂的,爬虫只是搜索引擎的一个子系统而已。下面介绍一个开源的爬虫框架Scrapy。

Scrapy是一个用 Python 写的 Crawler Framework ,简单轻巧,并且非常方便,并且官网上说已经在实际生产中在使用了,不过现在还没有 Release 版本,可以直接使用他们的 Mercurial 仓库里抓取源码进行安装。

Scrapy 使用 Twisted 这个异步网络库来处理网络通讯,架构清晰,并且包含了各种中间件接口,可以灵活的完成各种需求。整体架构如下图所示:

绿线是数据流向,首先从初始 URL 开始,Scheduler 会将其交给 Downloader 进行下载,下载之后会交给 Spider 进行分析,Spider 分析出来的结果有两种:一种是需要进一步抓取的链接,例如之前分析的“下一页”的链接,这些东西会被传回 Scheduler ;另一种是需要保存的数据,它们则被送到 Item Pipeline 那里,那是对数据进行后期处理(详细分析、过滤、存储等)的地方。另外,在数据流动的通道里还可以安装各种中间件,进行必要的处理。

 

分享到:
评论

相关推荐

    scapy-2.2.0

    Scapy runs natively on Linux, and on most Unixes with libpcap, libdnet and their respective python wrapper (see scapy's portability page). Scapy Scapy ≥ 2.x needs Python 2.5 or upcomming versions.

    Scapy-官方教程.7z

    Scapy官方教程 没错,就是你要找的。Philippe Biondi and the Scapy community build your own tools with scapy

    ARP-Spoofer, 使用Scapy的简单 ARP Spoofer.zip

    ARP-Spoofer, 使用Scapy的简单 ARP Spoofer 许可证版权所有 © 2015 Osanda Malith Jayathissa osanda@unseen.is 这里工作是免费的。 可以以重新分发它和/或者修改 public 许可以证的条款,版本 2,如 Sam Hocevar...

    Effective Python Penetration Testing

    You will learn to analyze network traffic by writing Scapy scripts and will see how to fingerprint web applications with Python libraries such as ProxMon and Spynner. Moving on, you will find out ...

    ScapySniffingAndSpoofing:此存储库包含SEED Labs使用Scapy进行嗅探和欺骗的源代码

    #SEED实验室嗅探和欺骗实验室您好,您可能是从“代码入口”博客来到这里的。 此存储库包含我发表过文章的“嗅探和欺骗SEED实验室”实验室报告的源代码。

    Understanding.Network.Hacks.Attack.and.Defense.with.Python

    Title: Understanding Network Hacks: Attack and Defense with Python Author: Bastian Ballmann Length: 178 pages Edition: 2015 Language: English ...Appendix A Scapy Reference Appendix B Secondary Links

    Black Hat PytHon Python Programming for Hackers and Pentesters

    To start, I lay down some networking fundamentals in Chapter 2 and slowly work our way through raw sockets in Chapter 3 and using Scapy in Chapter 4 for some more interesting network tooling....

    icmpdoor:用Python 3和Scapy编写的ICMP Reverse Shell(backdoorrev shell)

    icmpdoor是用Python3和scapy编写的ICMP rev shell。 已在Ubuntu 20.04,Debian 10(Kali Linux)和Windows 10上进行测试。 Python版本用法(Windows和Linux): ./icmp-cnc.py -i INTERFACE -d VICTIM-IP (Command...

    scapya-python-tool-for-security-testing-jcsb-1000182.pdf

    by correct sender and received by correct receiver. This is done mainly through digital certificates to ensure integrity of sender and receiver. Security testing terminologies 1. Unit Testing: ...

    黑客 python

    Chapter 4: Owning the Network with Scapy 47 Chapter 5: Web Hackery 61 Chapter 6: Extending Burp Proxy 75 Chapter 7: GitHub Command and Control 101 Chapter 8: Common Trojaning Tasks on Windows 111 ...

    sanicap:Python pcap消毒剂

    由于无法通过pip获得依赖项,因此Scapy的安装和运行可能会很麻烦,但此处提供了最佳文档: ##用法在另一个python脚本中>>> from sanicap import sanitize>>> sanicap.sanitize('/path/to/test.pcap', sequential=...

    Black Hat Python

    Chapter 4: Owning the Network with Scapy Chapter 5: Web Hackery Chapter 6: Extending Burp Proxy Chapter 7: GitHub Command and Control Chapter 8: Common Trojaning Tasks on Windows Chapter 9: Fun with...

    python生成式的send()方法(详解)

    随便在网上找了找,感觉都是讲半天讲不清楚,这里写一下。 def generator(): while True: receive=yield 1 print('extra'+str...send:Resumes the generator and “sends” a value that becomes the result o

Global site tag (gtag.js) - Google Analytics