Skip to content

Commit

Permalink
完善代理池
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris-code committed Aug 18, 2023
1 parent 099e39f commit 3550898
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/source_code/proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ ip:port
1. 编写代理池:例如在你的项目下创建个my_proxypool.py,实现下面的函数

```python
from feapder.network.proxy_pool import ProxyPool
from feapder.network.proxy_pool import BaseProxyPool

class MyProxyPool(ProxyPool):
class MyProxyPool(BaseProxyPool):
def get_proxy(self):
"""
获取代理
Expand Down
2 changes: 1 addition & 1 deletion feapder/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.7
1.8.8
4 changes: 2 additions & 2 deletions feapder/network/proxy_pool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
@author: Boris
@email: boris_liu@foxmail.com
"""
from .base import ProxyPool
from .memory_proxy_pool import MemoryProxyPool
from .base import BaseProxyPool
from .proxy_pool import ProxyPool
2 changes: 1 addition & 1 deletion feapder/network/proxy_pool/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from feapder.utils.log import log


class ProxyPool:
class BaseProxyPool:
@abc.abstractmethod
def get_proxy(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import requests

import feapder.setting as setting
from feapder.network.proxy_pool.base import ProxyPool
from feapder.network.proxy_pool.base import BaseProxyPool
from feapder.utils import metrics
from feapder.utils import tools


class MemoryProxyPool(ProxyPool):
class ProxyPool(BaseProxyPool):
"""
通过API提取代理,存储在内存中,无代理时会自动提取
API返回的代理以 \r\n 分隔
Expand Down
4 changes: 2 additions & 2 deletions feapder/network/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from feapder.db.redisdb import RedisDB
from feapder.network import user_agent
from feapder.network.downloader.base import Downloader, RenderDownloader
from feapder.network.proxy_pool import ProxyPool
from feapder.network.proxy_pool import BaseProxyPool
from feapder.network.response import Response
from feapder.utils.log import log

Expand All @@ -31,7 +31,7 @@

class Request:
user_agent_pool = user_agent
proxies_pool: ProxyPool = None
proxies_pool: BaseProxyPool = None

cache_db = None # redis / pika
cached_redis_key = None # 缓存response的文件文件夹 response_cached:cached_redis_key:md5
Expand Down
2 changes: 1 addition & 1 deletion feapder/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
PROXY_EXTRACT_API = None # 代理提取API ,返回的代理分割符为\r\n
PROXY_ENABLE = True
PROXY_MAX_FAILED_TIMES = 5 # 代理最大失败次数,超过则不使用,自动删除
PROXY_POOL = "feapder.network.proxy_pool.MemoryProxyPool" # 代理池
PROXY_POOL = "feapder.network.proxy_pool.ProxyPool" # 代理池

# 随机headers
RANDOM_HEADERS = True
Expand Down
2 changes: 1 addition & 1 deletion feapder/templates/project_template/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
# PROXY_EXTRACT_API = None # 代理提取API ,返回的代理分割符为\r\n
# PROXY_ENABLE = True
# PROXY_MAX_FAILED_TIMES = 5 # 代理最大失败次数,超过则不使用,自动删除
# PROXY_POOL = "feapder.network.proxy_pool.MemoryProxyPool" # 代理池
# PROXY_POOL = "feapder.network.proxy_pool.ProxyPool" # 代理池
#
# # 随机headers
# RANDOM_HEADERS = True
Expand Down

0 comments on commit 3550898

Please sign in to comment.