

docker快速启动proxy_pool项目 - z2n3
source link: https://www.cnblogs.com/z2n3/p/17429309.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

docker快速启动proxy_pool项目
项目地址:https://github.com/jhao104/proxy_pool
0x01 搭建redis
该项目是基于redis的,所以我们首先需要一个redis,这里我还是选择用docker快速启动一个
- 端口映射出来,可用于公网
docker run -d --name redis -p 6380:6379 redis --requirepass yourpassword
- 不端口映射,直接在vps上内部连接
docker run -d --name redis redis --requirepass yourpassword
0x02 查看容器内ip
如果你第一步中选择了映射,呢么就可以直接跳到0x03 启动项目 中直接运行了,如果不是,那么你就需要知道启动的实例的内网ip,但是当我们docker exec
进去的时候会发现并没有相关的ip addr
的环境,懒得安装了,直接在本机用如下命令
docker inspect redis
这里的redis是容器的name,在结果中找到如下所示即为容器内网ip(可与本机通信)
本机可以ping通
0x03 启动项目
直接替换密码,ip以及响应的端口即可,选择映射出来的话再开放防火墙策略就可以通过公网ip访问了
docker run -d --env DB_CONN=redis://:[email protected]:6379/0 -p 5010:5010 jhao104/proxy_pool:latest
0x04 简单使用
启动web服务后, 默认配置下会开启 http://127.0.0.1:5010 的api接口服务:
api | method | Description | params |
---|---|---|---|
/ | GET | api介绍 | None |
/get | GET | 随机获取一个代理 | 可选参数: ?type=https 过滤支持https的代理 |
/pop | GET | 获取并删除一个代理 | 可选参数: ?type=https 过滤支持https的代理 |
/all | GET | 获取所有代理 | 可选参数: ?type=https 过滤支持https的代理 |
/count | GET | 查看代理数量 | None |
/delete | GET | 删除代理 | ?proxy=host:ip |
如果要在爬虫代码中使用的话, 可以将此api封装成函数直接使用,例如:
import requests
def get_proxy():
return requests.get("http://127.0.0.1:5010/get/").json()
def delete_proxy(proxy):
requests.get("http://127.0.0.1:5010/delete/?proxy={}".format(proxy))
# your spider code
def getHtml():
# ....
retry_count = 5
proxy = get_proxy().get("proxy")
while retry_count > 0:
try:
html = requests.get('http://www.example.com', proxies={"http": "http://{}".format(proxy)})
# 使用代理访问
return html
except Exception:
retry_count -= 1
# 删除代理池中代理
delete_proxy(proxy)
return None
剩下具体的可以去github看文档
0x05 后续
后续的话可以使用docker-compose,然后编写yml文件等等操作来实现更“自动化”
__EOF__
Recommend
-
121
proxy_pool - ip proxy pool
-
10
Traefik Reverse Proxy with Docker Compose and Docker Swarm February 17, 2021 Reading time ~8 minutes ...
-
9
如何基于 Docker 快速搭建 Springboot + Mysql + Redis 项目 [TOC]有时候我们需要快速启动一些项目,但是环境往往折腾了好久,因此弄一个可以重用的快速搭建的教程,docker
-
8
How to Install and Use Nginx Proxy Manager with Docker A reverse proxy is a web server that can sit in front of another web server or a web service. It can encrypt outgoing traffic, act as a load balancer, redirect traffic, and offe...
-
15
Docker Container · GitHub Traefik Reverse Proxy - Mosquitto MQTT Broker - Docker Container This gist is to configure a Mosquitto MQTT Broker behind a Traefik reverse-p...
-
5
Installing IBM CloudPaks with a Nexus Proxy Docker Registry Installing IBM CloudPaks with a Nexus Proxy Docker Registry Jun 27, 2022 • Category
-
3
Nest.js快速启动API项目更新日期: 2022-10-09阅读: 254标签: api分享
-
10
openldap docker-compose快速启动以及常见操作 精选 原创 lyy910203 2022-10-18...
-
9
【笔记】SpringBoot项目快速启动 2022-10-18
-
4
caddy-docker-proxy works by listening to docker events, and when it sees a container or service that has a caddy label will automatically configure a
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK