python 编写的DHT Crawler 网络爬虫

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wyl9527/article/details/82289664

1、安装boost依赖和编译环境。

yum install -y boost boost-devel

yum install -y make gcc gcc-c++ kernel-devel python-devel

2、装 libtorrent 的 python 绑定库

#下载到本地
cd  /opt/software

wget https://github.com/arvidn/libtorrent/releases/download/libtorrent-1_0_10/libtorrent-rasterbar-1.0.10.tar.gz


#解压
cd  /opt/software/libtorrent-rasterbar-1.0.10.tar.gz
tar  -xf  libtorrent-rasterbar-1.0.10.tar.gz -C /opt


#编译,安装,根据系统性能,虚拟机上时间有点长
./configure --disable-debug --with-boost-libdir=/usr/lib64 --disable-encryption --enable-python-binding
make && make install


#配置库文件环境变量
export LD_LIBRARY_PATH=/usr/local/lib/

#绑定
cd bindings/python
python setup.py build
python setup.py install

3、安装 twisted 网络库

pip install twisted

4、开放防火墙的对应端口段,目前默认的是 32900--32920 (20是工作的p2p客户端数量)

这里我们的虚拟机的防火墙是关闭的状态。

5、运行方法

  • 下载 collector.py collectord.py 文件到安装目录
git clone  https://github.com/blueskyz/DHTCrawler.git
  • 脚本方式测试运行:
 python collector.py result.json collector.state
  • 服务方式运行:
twistd -y collectord.py

6、查看结果:

猜你喜欢

转载自blog.csdn.net/wyl9527/article/details/82289664
今日推荐