1
resposta

Dando erro bem no começo do Curso Scraping Com Python: coleta de dados na web, no primeiro exemplo....

No inicio do Curso Scraping Com Python: coleta de dados na web na célula 1.3 do Jupyter Notebook é pedido pra rodar esse código:

from urllib.request import urlopenfrom bs4 import BeautifulSoupurl='http://alura-site-scraping.herokuapp.com/hello-world.php' response=urlopen(url) html=response.read()

Ao tentar rodar aprece esse erro (O que faço pra resolver, isso?): (ACABO DE NOTAR TAMBÉM: por vezes não acontece nada. O compilador roda a célula, pula pra célula seguinte e nada aparece.)


gaierror Traceback (most recent call last) ~\Anaconda3_THAT\lib\urllib\request.py in do_open(self, http_class, req, **http_conn_args) 1316 h.request(req.get_method(), req.selector, req.data, headers, -> 1317 encode_chunked=req.has_header('Transfer-encoding')) 1318 except OSError as err: # timeout error

~\Anaconda3_THAT\lib\http\client.py in request(self, method, url, body, headers, encode_chunked) 1243 """Send a complete request to the server.""" -> 1244 self.sendrequest(method, url, body, headers, encode_chunked) 1245

~\Anaconda3_THAT\lib\http\client.py in sendrequest(self, method, url, body, headers, encode_chunked) 1289 body = encode(body, 'body') -> 1290 self.endheaders(body, encodechunked=encode_chunked) 1291

~\Anaconda3_THAT\lib\http\client.py in endheaders(self, message_body, encode_chunked) 1238 raise CannotSendHeader() -> 1239 self.sendoutput(message_body, encode_chunked=encode_chunked) 1240

~\Anaconda3_THAT\lib\http\client.py in sendoutput(self, message_body, encode_chunked) 1025 del self._buffer[:] -> 1026 self.send(msg) 1027

~\Anaconda3_THAT\lib\http\client.py in send(self, data) 965 if self.auto_open: --> 966 self.connect() 967 else:

~\Anaconda3_THAT\lib\http\client.py in connect(self) 937 self.sock = self.createconnection( --> 938 (self.host,self.port), self.timeout, self.source_address) 939 self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

~\Anaconda3_THAT\lib\socket.py in create_connection(address, timeout, source_address) 706 err = None --> 707 for res in getaddrinfo(host, port, 0, SOCK_STREAM): 708 af, socktype, proto, canonname, sa = res

~\Anaconda3_THAT\lib\socket.py in getaddrinfo(host, port, family, type, proto, flags) 747 addrlist = [] --> 748 for res in _socket.getaddrinfo(host, port, family, type, proto, flags): 749 af, socktype, proto, canonname, sa = res

gaierror: [Errno 11002] getaddrinfo failed

During handling of the above exception, another exception occurred:

URLError Traceback (most recent call last) in 4 from bs4 import BeautifulSoup 5 url='http://alura-site-scraping.herokuapp.com/hello-world.php' ----> 6 response=urlopen(url) 7 html

~\Anaconda3_THAT\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context) 220 else: 221 opener = opener --> 222 return opener.open(url, data, timeout) 223 224 def installopener(opener):

~\Anaconda3_THAT\lib\urllib\request.py in open(self, fullurl, data, timeout) 523 req = meth(req) 524 --> 525 response = self._open(req, data) 526 527 # post-process response

~\Anaconda3_THAT\lib\urllib\request.py in open(self, req, data) 541 protocol = req.type 542 result = self.call_chain(self.handle_open, protocol, protocol + --> 543 '_open', req) 544 if result: 545 return result

~\Anaconda3_THAT\lib\urllib\request.py in callchain(self, chain, kind, meth_name, args) 501 for handler in handlers: 502 func = getattr(handler, meth_name) --> 503 result = func(args) 504 if result is not None: 505 return result

~\Anaconda3_THAT\lib\urllib\request.py in http_open(self, req) 1343 1344 def http_open(self, req): -> 1345 return self.do_open(http.client.HTTPConnection, req) 1346 1347 http_request = AbstractHTTPHandler.do_request_

~\Anaconda3_THAT\lib\urllib\request.py in do_open(self, http_class, req, **http_conn_args) 1317 encode_chunked=req.has_header('Transfer-encoding')) 1318 except OSError as err: # timeout error -> 1319 raise URLError(err) 1320 r = h.getresponse() 1321 except:

URLError: <urlopen error [Errno 11002] getaddrinfo failed>

1 resposta

Olá Cristiane,

O problema provavelmente é no link https://alura-site-scraping.herokuapp.com/hello-world.php

Eu acessei agora e abriu, então testa o seu código novamente por favor. Pelo que eu vi você pode abrir https://alura-site-scraping.herokuapp.com/ no seu navegador para identificar se a página está fora do ar ou não.

Vou entrar em contato com a equipe para verificar o que aconteceu para a página ficar fora do ar.

Espero ter ajudado, qualquer dúvida é só falar!