新手在初学爬虫内容时遇到Python问题,希望各位能赐教
程序代码:
import urllib.request proxy_handler = urllib.request.ProxyHandler( { 'http': 'http://127.0.0.1:9743', 'https': 'https://127.0.0.1:9743' } ) opener = urllib.request.build_opener(proxy_handler) response = opener.open('http://www.baidu.com') print(response.read())
出现以下错误结果:
C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\python.exe C:/Users/Administrator/AppData/Local/Programs/Python/Python37-32/spiders/基本库的使用.py
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1016, in _send_output
self.send(msg)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 956, in send
self.connect()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 928, in connect
(self.host,self.port), self.timeout, self.source_address)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 727, in create_connection
raise err
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 716, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
请问如何解决???