May-09-2022, 02:29 PM
Hi!
I’m new with Python and I have been following some tutorials and based on one of them I have the following piece of code:
The URL is easily accessed through a browser but when I run the code I got the following errors:
I’m new with Python and I have been following some tutorials and based on one of them I have the following piece of code:
from scrapy import Selector from urllib.request import urlopen html = urlopen("https://www.pythonparatodos.com.br/formulario.html") sel = Selector(text = html.read()) lista = sel.xpath('//input[@type="text"]') print(lista) for selector in lista: print(selector)Thanks in advance!The URL is easily accessed through a browser but when I run the code I got the following errors:
Error:C:\Users\username\Envs\webcrawler_part_ii\Scripts\python.exe C:/Users/username/PycharmProjects/webcrawler_part_ii/aula44_scrapy_lxml_exemplos.py Traceback (most recent call last): File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1346, in do_open h.request(req.get_method(), req.selector, req.data, headers, File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1257, in request self._send_request(method, url, body, headers, encode_chunked) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1303, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1252, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1012, in _send_output self.send(msg) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 952, in send self.connect() File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1426, in connect self.sock = self._context.wrap_socket(self.sock, File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 500, in wrap_socket return self.sslsocket_class._create( File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1040, in _create self.do_handshake() File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1309, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\username\PycharmProjects\webcrawler_part_ii\aula44_scrapy_lxml_exemplos.py", line 5, in <module> html = urlopen("https://www.pythonparatodos.com.br/formulario.html") File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 214, in urlopen return opener.open(url, data, timeout) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 517, in open response = self._open(req, data) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 534, in _open result = self._call_chain(self.handle_open, protocol, protocol + File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain result = func(*args) File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1389, in https_open return self.do_open(http.client.HTTPSConnection, req, File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 1349, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129)> Process finished with exit code 1I’ve found some possible solutions on google to this with certifi or with the two lines of code below but none of them worked. Can someone help me on this?import ssl ssl._create_default_https_context = ssl._create_unverified_context
