python3配置socks5代理进行爬取

python3配置socks5代理进行爬取[Python常见问题]

一.代码

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import requests
import socket
import socks

SOCKS5_PROXY_HOST = "xxxx"		 # socks 代理IP地址
SOCKS5_PROXY_PORT = xxx           # socks 代理本地端口
default_socket = socket.socket
socks.set_default_proxy(socks.SOCKS5, SOCKS5_PROXY_HOST, SOCKS5_PROXY_PORT)
socket.socket = socks.socksocket

session = requests.session()
session.keep_alive = False

res=session.get("http://ipconfig.cc/",timeout=5)
print(res.text)
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » python3配置socks5代理进行爬取