Skip to content

Commit f1b2dac

Browse files
committed
完善代理池文档
1 parent 644a552 commit f1b2dac

1 file changed

Lines changed: 46 additions & 9 deletions

File tree

docs/source_code/proxy.md

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# 代理使用说明
22

3-
代理使用有两种方式
4-
1. 用框架内置的代理池
5-
2. 自己写
3+
代理使用有三种方式
4+
1. 使用框架内置代理池
5+
2. 自定义代理池
6+
3. 请求中直接指定
67

7-
## 1. 框架内置的代理池
8+
## 方式1. 使用框架内置代理池
89

9-
### 基本使用
10+
### 配置代理
1011

1112
在配置文件中配置代理提取接口
1213

@@ -27,7 +28,7 @@ ip:port
2728

2829
这样feapder在请求时会自动随机使用上面的代理请求了
2930

30-
### 高阶
31+
## 管理代理
3132

3233
1. 删除代理(默认是请求异常连续5次,再删除代理)
3334

@@ -46,10 +47,46 @@ ip:port
4647
request.del_proxy()
4748

4849
```
50+
51+
## 方式2. 自定义代理池
52+
53+
1. 编写代理池:例如在你的项目下创建个my_proxypool.py,实现下面的函数
54+
55+
```python
56+
from feapder.network.proxy_pool import ProxyPool
57+
58+
59+
class MyProxyPool(ProxyPool):
60+
def get_proxy(self):
61+
"""
62+
获取代理
63+
Returns:
64+
{"http": "xxx", "https": "xxx"}
65+
"""
66+
pass
67+
68+
def del_proxy(self, proxy):
69+
"""
70+
@summary: 删除代理
71+
---------
72+
@param proxy: xxx
73+
"""
74+
pass
75+
```
76+
77+
3. 修改setting的代理配置
78+
79+
```
80+
PROXY_POOL = "my_proxypool.MyProxyPool" # 代理池
81+
```
82+
83+
将编写好的代理池配置进来,值为类的模块路径,需要指定到具体的类名
84+
85+
4986

50-
## 2. 自己写
87+
## 方式3. 不使用代理池,直接给请求指定代理
5188

52-
自己写就比较灵活,自己随机取个代理,然后给request赋值即可,例如在下载中间件里使用
89+
直接给request.proxies赋值即可,例如在下载中间件里使用
5390

5491
```python
5592
import feapder
@@ -59,7 +96,7 @@ class TestProxy(feapder.AirSpider):
5996
yield feapder.Request("https://www.baidu.com")
6097

6198
def download_midware(self, request):
62-
# 这里随机取个代理使用即可
99+
# 这里使用代理使用即可
63100
request.proxies = {"https": "https://ip:port", "http": "http://ip:port"}
64101
return request
65102

0 commit comments

Comments
 (0)