python3配置socks5代理进行爬取

一.代码

#!/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)
posted @ 2020-10-15 18:04  小小咸鱼YwY  阅读(3162)  评论(0编辑  收藏  举报