'Can we use Tor in Python program?
I try to use or change IP address and do web scraping on public data accessible by all but I can't find a solution. I am trying to do a rotating ip address. I'm on Windows 10 and the Anaconda IDE. For example, i execute this code below:
import requests
domain = "https://www.undernews.fr"
#define your proxies
#the socks5h method allows the socks server to translate the #hostname. So make sure that you add 'socks5h'.
proxies = {
'http': 'socks5h://127.0.0.1:9050',
'https': 'socks5h://127.0.0.1:9050'
}
a = requests.get(domain.strip(), proxies=proxies).text
print(a)
And my kernel return:
File "C:\Users\FirstName\anaconda3\lib\site-packages\requests\adapters.py", line 519, in send
raise ConnectionError(e, request=request)
ConnectionError: SOCKSHTTPSConnectionPool(host='www.undernews.fr', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x000001CF0D4EA3A0>: Failed to establish a new connection: [WinError 10061] Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée'))
Solution 1:[1]
It looks like those proxies have been blocked:
Translated part of your error: "No connection could be established because the target computer expressly refused it"
Maybe try looking into using proxyscrape to get a list of "free" proxies. Or at least try with a different proxy IP
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SPYBUG96 |
