Yes, it is possible to use the Requests library with a SOCKS proxy in Python. However, this functionality is not built directly into Requests; you will need to install an additional dependency called requests[socks]
to enable SOCKS support.
Here's how you can install the necessary package using pip
:
pip install requests[socks]
Or, if you prefer to install the dependencies separately:
pip install requests pysocks
Once you have the required package(s) installed, you can use a SOCKS proxy with Requests by specifying the proxies
parameter in your request. Here's an example of how to use a SOCKS proxy:
import requests
proxies = {
'http': 'socks5://user:password@host:port',
'https': 'socks5://user:password@host:port'
}
response = requests.get('http://example.com', proxies=proxies)
print(response.text)
Replace user
, password
, host
, and port
with your actual SOCKS proxy credentials and server information.
Please note that when using SOCKS proxies, you can specify socks5
or socks4
as the protocol depending on what your proxy server supports.
Keep in mind that while web scraping, you should always respect the terms of service of the website, check robots.txt
for scraping permissions, and ensure that your actions are legal and ethical.