使用Nutch爬取暗网(.onion)

    抱着学习的态度,简单翻译了一个正在使用的教程,水平有限,如有错误多多包涵,自己也是刚接触到这个东西很多都不是很明白,需要解下来具体实践一下才能清楚,在这里简单贴一下译文,希望能帮助需要的人:

使用Nutch爬取暗网(.onion)
目录:
1.使用Nutch爬取隐藏服务(.onion)
    1.重要提示
	2.介绍
	3.快速入门
	4.安装Tor
	    1.Debian 或者 Ubuntu
		2.Mac OSX
		3.从git克隆源码
	5.Tor日志
	6.Socks代理异常
	    1.Polipo配置
		    1.在Debian或Ubuntu上
			2.在Mac OSX上
		2.代理
		    1.在Debian或Ubuntu上
			2.在Mac OSX上
	7.Nutch爬虫配置
	8.结论
	
	
重要提示:
教程的目的是解释如何爬取隐藏服务而非怎么去使用隐藏服务来爬取。这是在读取和使用TOr网络的时候都应该考虑到的。通过Tor网络来爬取正常的网站无疑会加重Tor的网络负载。但是在Tor中你可以突破网络的封锁,访问到你想访问的网站,但是如果你执意想使用Tor和Nutch来爬取常规网站的话,你肯定走错地方了。
介绍:
Tor是一个虚拟的网络通道,能够保证用户的隐私安全,也能够为软件开发者使用内置的隐私特性创造新的的沟通工具。Tor提供了广泛的应用基础,允许组织机构和个人共享他们的信息而不用考虑隐私的问题。这个教程提供了一个端到端的实例进入到Tor网络使用Nutch爬虫来爬去“.onion”网页
快速入门:
这个教程在Debian和Ubuntu已经完成测试,也可以在Mac OSX上运行。
Tor安装:
从这里下载安装配置代理相关即可,详情百度
https://www.torproject.org/
Debian or Ubuntu:
可以参考这里安装:https://www.torproject.org/docs/debian
也可以使用命令:apt-get install tor 
Mac OSX:
使用命令: brew install tor,之后使用tor可看到下面提示:
lmcgibbn@LMC-032857 /usr/local/tor(master) $ tor
Sep 23 17:09:47.448 [notice] Tor v0.2.4.23 (git-598c61362f1b3d3e) running on Darwin with Libevent 2.0.21-stable and OpenSSL 1.0.1i.
Sep 23 17:09:47.448 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
Sep 23 17:09:47.449 [notice] Configuration file "/usr/local/etc/tor/torrc" not present, using reasonable defaults.
Sep 23 17:09:47.452 [notice] Opening Socks listener on 127.0.0.1:9050
Sep 23 17:09:47.000 [notice] Parsing GEOIP IPv4 file /usr/local/Cellar/tor/0.2.4.23_1/share/tor/geoip.
Sep 23 17:09:47.000 [notice] Parsing GEOIP IPv6 file /usr/local/Cellar/tor/0.2.4.23_1/share/tor/geoip6.
Sep 23 17:09:48.000 [notice] Bootstrapped 5%: Connecting to directory server.
Sep 23 17:09:48.000 [notice] Bootstrapped 10%: Finishing handshake with directory server.
Sep 23 17:09:49.000 [notice] Bootstrapped 15%: Establishing an encrypted directory connection.
Sep 23 17:09:49.000 [notice] Bootstrapped 20%: Asking for networkstatus consensus.
Sep 23 17:09:49.000 [notice] Bootstrapped 25%: Loading networkstatus consensus.

Sep 23 17:10:12.000 [notice] We now have enough directory information to build circuits.
Sep 23 17:10:12.000 [notice] Bootstrapped 80%: Connecting to the Tor network.
Sep 23 17:10:12.000 [notice] Bootstrapped 90%: Establishing a Tor circuit.
Sep 23 17:10:12.000 [notice] Tor has successfully opened a circuit. Looks like client functionality is working.
Sep 23 17:10:12.000 [notice] Bootstrapped 100%: Done.
从Git克隆源码:
git clone https://git.torproject.org/git/tor
cd tor
./autogen.sh && ./configure --disable-asciidoc && make
src/or/tor
之后可以看到有一个socks代理在localhost:9050端口已经启动
Tor日志:
可以配置Tor的日志文件:
进入:/etc/tor/torrc
修改如下
SafeLogging 0
LogTimeGranularity 1 
socks代理异常:
如果使用Nutch你的爬虫不能够和socks代理进行交互的话,你需要使用http代理然后配置你代理文件使用socks代理,为了能够实现这个功能我们可以选用下述一个代理:
Polipo:
Polipo是一个小型的代理服务器软件, 被设计为一个人或者几个人使用的代理服务器软件,可以作为http代理使用,而且有缓存功能。也可以作为将SOCKS代理转为http代理的工具。默认使用 8123 作为http代理端口。
首页地址:http://www.pps.univ-paris-diderot.fr/~jch/software/polipo/
源码下载地址:http://www.pps.univ-paris-diderot.fr/~jch/software/files/polipo/
在Debian或Ubuntu上:
使用命令:apt-get install polipo
在Mac OSX上:
使用命令:brew install polipo
接下来使用该链接来配置你的Polipo:http://www.pps.univ-paris-diderot.fr/~jch/software/polipo/tor.html
代理Privoxy:
Privoxy是一个具有过滤功能的非缓存的网络代理能够提高隐私性,修改页面数据、HTTP报文头、控制访问、移除地址和其他网络垃圾。Privoxy配置很灵活可以被用户个性化的配置使用。
在Debian或Ubuntu上:
使用命令:apt-get install privoxy
在Mac OSX上:
使用命令:brew install privoxy
配置Privoxy可参考:
http://www.privoxy.org/faq/misc.html#TOR
Nutch爬虫配置:
配置Nutch只追寻域名以“.onion”结束的网址,这个可以通过简单的url过滤的方式实现,可以参考具体的实现教程:https://wiki.apache.org/nutch/NutchTutorial
结论:
该教程演示了如何使用Tor和Nutch来获取暗网的数据。