File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change 18
18
19
19
### Docker
20
20
21
- 如果使用 Docker,则需要安装了如下环境 :
21
+ 如果使用 Docker,则需要安装如下环境 :
22
22
23
23
* Docker
24
24
* Docker-Compose
27
27
28
28
常规方式要求有 Python 环境、Redis 环境,具体要求如下:
29
29
30
- * Python: >=3.6
30
+ * Python>=3.6
31
31
* Redis
32
32
33
33
## Docker 运行
@@ -89,7 +89,10 @@ export REDIS_CONNECTION_STRING='redis://[password]@host:port'
89
89
90
90
### 安装依赖包
91
91
92
- 这里强烈推荐使用 Conda 或 VirtualEnv 创建虚拟环境,然后 pip 安装依赖即可:
92
+ 这里强烈推荐使用 [ Conda] ( https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands )
93
+ 或 [ virtualenv] ( https://virtualenv.pypa.io/en/latest/user_guide.html ) 创建虚拟环境,Python 版本不低于 3.6。
94
+
95
+ 然后 pip 安装依赖即可:
93
96
94
97
``` shell script
95
98
pip3 install -r requirements.txt
@@ -121,7 +124,7 @@ python3 run.py --processor server
121
124
122
125
成功运行之后可以通过 [ http://localhost:5555/random ] ( http://localhost:5555/random ) 获取一个随机可用代理。
123
126
124
- 可以用程序对接实现,简单的示例展示了获取代理并爬取网页的过程 :
127
+ 可以用程序对接实现,下面的示例展示了获取代理并爬取网页的过程 :
125
128
126
129
``` python
127
130
import requests
@@ -233,7 +236,7 @@ export REDIS_KEY=proxies:weibo
233
236
234
237
如果使用 Docker-Compose 启动代理池,则需要在 docker-compose.yml 文件里面指定环境变量,如:
235
238
236
- ``` shell script
239
+ ``` yaml
237
240
version : ' 3'
238
241
services :
239
242
redis :
@@ -256,9 +259,9 @@ services:
256
259
REDIS_KEY : proxies:weibo
257
260
` ` `
258
261
259
- ## 扩展代理
262
+ ## 扩展代理爬虫
260
263
261
- 代理的爬虫均放置在 proxypool/crawlers 文件夹下,目前对接了有限的爬虫 。
264
+ 代理的爬虫均放置在 proxypool/crawlers 文件夹下,目前对接了有限几个代理的爬虫 。
262
265
263
266
若扩展一个爬虫,只需要在 crawlers 文件夹下新建一个 Python 文件声明一个 Class 即可。
264
267
Original file line number Diff line number Diff line change 6
6
BASE_URL = 'http://www.664ip.cn/{page}.html'
7
7
MAX_PAGE = 5
8
8
9
+
9
10
class Daili66Crawler (BaseCrawler ):
10
11
"""
11
12
daili66 crawler, http://www.66ip.cn/1.html
12
13
"""
13
14
urls = [BASE_URL .format (page = page ) for page in range (1 , MAX_PAGE + 1 )]
14
15
15
-
16
16
def parse (self , html ):
17
17
"""
18
18
parse html file to get proxies
@@ -25,6 +25,7 @@ def parse(self, html):
25
25
port = int (tr .find ('td:nth-child(2)' ).text ())
26
26
yield Proxy (host = host , port = port )
27
27
28
+
28
29
if __name__ == '__main__' :
29
30
crawler = Daili66Crawler ()
30
31
for proxy in crawler .crawl ():
You can’t perform that action at this time.
0 commit comments