Webscraping with Python: WinError 10061: Target ma

2019-08-09 04:11发布

问题:

I am writing a code to scrape data from a website. The code was working fine until I decided to hide my IP address. I get the following error "urlopen error [WinError 10061] No connection could be made because the target machine actively refused it"

I have disabled the firewalls and antivirus on my machine; Tor is installed and running, internet connection is fine (obviously). Could someone help me figure out where the problem is? And whether it can be fixed (I cannot change the website I am scraping data from.)?

Here is the code:

list_url= ["http://www.url.com"]
proxy_support = urllib.request.ProxyHandler({"http":"http://127.0.0.1:8118"})  
opener = urllib.request.build_opener(proxy_support)  
urllib.request.install_opener(opener)

for url in list_url:
 base_url_parts = urllib.parse.urlparse(url)
 while True:
    raw_html = urllib.request.build_opener(proxy_support).open(url).read()
...