1. 程式人生 > >requests支援socks5代理了

requests支援socks5代理了

記錄下
以前:

import socket
import socks
from requests_html import HTMLSession
session=HTMLSession()
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 1080)
socket.socket = socks.socksocket
url = "https://www.google.co.jp"
print(session.get(url).text)

現在:

from requests_html import HTMLSession

session = HTMLSession()
proxy = {"http": "socks5://127.0.0.1:1080","https": "socks5://127.0.0.1:1080"}
url = "https://www.google.co.jp"
req = session.get(url, proxies=proxy)
print(req.text)