它将易用性与 Tor 强大的隐私特性相结合,实现安全且不可追踪的数据收集。无论对新手还是经验丰富的程序员而言,这款工具都是数字时代负责任数据采集的必备之选。
[![Release][release-version-shield]][releases-link] [![Last Commit][last-commit-shield]][commit-link] ![Python][python-version-shield] [![Quality Gate Status][quality-gate-shield]][quality-gate-link] [![license][license-shield]][license-link]
如果你是终端狂热爱好者,你就知道事情必须简单明了。将输出传递给其他工具是必要的,而准确性是关键。
只需一个参数,你就可以通过 TOR 网络读取 .onion 网页或普通网页,并且通过使用管道,你可以将输出传递给任何你偏好的其他工具。
$ torcrawl -u http://www.github.com/ | grep 'google-analytics'
<meta-name="google-analytics" content="UA-XXXXXX- ">
如果你想爬取网页中的链接,可以使用 -c,BAM 就能把所有内部链接保存到一个文件中。你甚至可以用 -d 继续爬取这些链接,以此类推。你还可以使用参数 -p 在下次爬取前等待若干秒。
$ torcrawl -v -u http://www.github.com/ -c -d 2 -p 2
# TOR is ready!
# URL: http://www.github.com/
# Your IP: XXX.XXX.XXX.XXX
# Crawler started from http://www.github.com/ with 2 depth crawl and 2 second(s) delay:
# Step 1 completed with: 11 results
# Step 2 completed with: 112 results
# File created on /path/to/project/links.txt
[!TIP]
爬取本身并不违法,但侵犯版权是违法的。在开始爬取网站之前,最好先仔细查看该网站的服务条款(T&C)。有些网站会设置所谓的robots.txt,用来告知爬虫不要访问那些页面。
本爬虫会允许你绕过这一限制,但我们始终建议尊重 robots.txt。
pip install torcrawlgit clone https://github.com/MikeMeliz/TorCrawl.py.gitpip install -r requirements.txtapt-get install torservice tor starttor.exe][tor-download],然后执行:tor.exe --service installtor.exe --service startbrew install torbrew services start tor| 参数 | 长参数 | 描述 |
|---|---|---|
| 通用: | ||
| -h | --help | 帮助信息 |
| -v | --verbose | 显示更多进度信息 |
| -u | --url *.onion | 要爬取或提取的网页 URL |
| -w | --without | 不使用 TOR 网络 |
| -rua | --random-ua | 为请求启用随机 user-agent 轮换 |
| -rpr | --random-proxy | 从 res/proxies.txt 启用随机代理轮换(需要 -w 标志,每行一个代理,格式:host:port) |
| -px | --proxy | SOCKS5 代理的 IP 地址(默认:127.0.0.1,用于 TOR) |
| -pr | --proxyport | SOCKS5 代理的端口(默认:9050) |
| -f | --folder | 用于存放生成文件的目录 |
| -V | --version | 显示版本并退出 |
| 提取: | ||
| -e | --extract | 将页面代码提取到终端或文件(默认:终端) |
| -i | --input filename | 包含 URL 的输入文件(按行分隔) |
| -o | --output [filename] | 将页面输出到文件(用于单个页面) |
| -y | --yara | 执行 yara 关键词搜索: h = 搜索整个 html 对象, t = 仅搜索文本 |
| 爬取: | ||
| -c | --crawl | 爬取网站(默认输出到 website/links.txt) |
| -d | --depth | 设置爬虫的爬取深度(默认:1) |
| -p | --pause | 请求之间的暂停秒数(默认:0) |
| -j | --json | 除 txt 输出外,还将爬取结果导出为 JSON |
| -x | --xml | 除 txt 输出外,还将爬取结果导出为 XML |
| -DB | --database | 将爬取结果和链接图导出到 SQLite 数据库 |
| -vis | --visualization | 从 SQLite 数据库生成 HTML 可视化(需要 -DB) |
| -l | --log | 记录已访问 URL 及其响应码的日志文件 |
仅将单个网页提取到终端:
$ python torcrawl.py -u http://www.github.com
<!DOCTYPE html>
...
</html>
提取到文件(github.htm)中,不使用 TOR:
$ python torcrawl.py -w -u http://www.github.com -o github.htm
## File created on /script/path/github.htm
在终端中提取,并仅查找包含 google-analytics 的那一行:
$ python torcrawl.py -u http://www.github.com | grep 'google-analytics'
<meta name="google-analytics" content="UA-*******-*">
提取到文件并使用 yara 仅查找包含 google-analytics 的行:
$ python torcrawl.py -v -w -u https://github.com -e -y 0
...
注意: 更新 res/keyword.yar 以搜索其他关键词。
使用 -y 0 进行原始 HTML 搜索,使用 -y 1 仅进行文本搜索。
将一组网页(从文件导入)提取到终端:
$ python torcrawl.py -i links.txt
...
在不使用 TOR 的情况下爬取网页链接,同时显示详细输出(非常有用):
$ python torcrawl.py -v -w -u http://www.github.com/ -c
## URL: http://www.github.com/
## Your IP: *.*.*.*
## Crawler Started from http://www.github.com/ with step 1 and wait 0
## Step 1 completed with: 11 results
## File created on /script/path/links.txt
以深度 2(2 次点击)爬取网页,并在爬取下一页之前等待 5 秒:
$ python torcrawl.py -v -u http://www.github.com/ -c -d 2 -p 5
## TOR is ready!
## URL: http://www.github.com/
## Your IP: *.*.*.*
## Crawler Started from http://www.github.com with step 2 and wait 5
## Step 1 completed with: 11 results
## Step 2 completed with: 112 results
## File created on /script/path/links.txt
你可以用一条命令同时爬取页面并将网页提取到文件夹中:
$ python torcrawl.py -v -u http://www.github.com/ -c -d 2 -p 5 -e
## TOR is ready!
## URL: http://www.github.com/
## Your IP: *.*.*.*
## Crawler Started from http://www.github.com with step 1 and wait 5
## Step 1 completed with: 11 results
## File created on /script/path/FolderName/index.htm
## File created on /script/path/FolderName/projects.html
## ...
注意: 爬虫链接的默认(也是目前唯一的)文件是 links.txt 文档。此外,要在爬取后立即提取,你必须提供 -e 参数
按照同样的逻辑,你可以解析所有这些页面以进行 grep(例如)并搜索特定文本:
$ python torcrawl.py -u http://www.github.com/ -c -e | grep '</html>'
</html>
</html>
...
你可以用一条命令爬取页面、执行关键词搜索,并将匹配结果的网页提取到一个文件夹中:
$ python torcrawl.py -v -u http://www.github.com/ -c -d 2 -p 5 -e -y h
## TOR is ready!
## URL: http://www.github.com/
## Your IP: *.*.*.*
## Crawler Started from http://www.github.com with step 1 and wait 5
## Step 1 completed with: 11 results
## File created on /script/path/FolderName/index.htm
## File created on /script/path/FolderName/projects.html
## ...
注意: 更新 res/keyword.yar 以搜索其他关键词。
使用 -y h 进行原始 html 搜索,使用 -y t 仅进行文本搜索。
![TorCrawl-Demo][demo]
欢迎为本项目做出贡献!只需 fork 本项目,在你的 fork 上进行任意修改,并向当前分支提交 pull request 即可!
:shipit: 任何建议、帮助或问题都将不胜感激!:shipit:
“GPL”代表“General Public License”(通用公共许可证)。使用 GNU GPL 将要求所有发布的改进版本都必须是自由软件([更多信息][gpl-faq])。