# 代理

### socks5 代理

```python
import requests

# 代理提取API
proxy_url = 'http://proxy.siyetian.com/apis_get.html?token=MesJWLNp2Y35keJdXTqV1dNRVT45ERVdnT31STqFUeNpXQ10EVBl3TE1UNPR1Yx8ERjFTTE1ke.QO4MTOxMDOzcTA&limit=2&type=1&time=&data_format=json'

headers = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
}

# 使用API提取代理
res_proxies = requests.get(proxy_url, headers=headers).json()
print(res_proxies)
# 构建代理池
proxies_pool = []
for ip_item in res_proxies['data']:
    socks5 = f"socks5://{ip_item['ip']}:{ip_item['port']}"
    proxy = {'http': socks5, 'https': socks5}
    proxies_pool.append(proxy)
print(proxies_pool)

# 测试代理
for i in range(0, 2):
    choice_proxy = proxies_pool[i]

    url = "https://httpbin.org/ip"
    response = requests.get(url, headers=headers, proxies=choice_proxy)

    print(f'{i}:', response.text)

```
