###前提・実現したいこと
オライリーのPythonによるwebスクレイピングを見ながら勉強を進めている初心者です。
https://en.wikipedia.org/wiki/Kevin_Bacon
上記、URLからhrefを取ってきたのですが、下記のながーいエラーが出てしまいます。
コードではなく環境が間違ってるのと思うのですが、アドバイスをいただけますか?
###発生している問題・エラーメッセージ
エラーメッセージ Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_ open encode_chunked=req.has_header('Transfer-encoding')) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in reques t self._send_request(method, url, body, headers, encode_chunked) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_ request self.endheaders(body, encode_chunked=encode_chunked) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endhea ders self._send_output(message_body, encode_chunked=encode_chunked) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_ output self.send(msg) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send self.connect() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connec t server_hostname=server_hostname) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 407, in wrap_socket _context=self, _session=session) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 814, in __init__ self.do_handshake() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1068, in do_handshake self._sslobj.do_handshake() <中略> During handling of the above exception, another exception occurred: Traceback (most recent call last): File "wiki.py", line 5, in <module> html = urlopen("https://en.wikipedia.org/wiki/Kevin_Bacon") File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlo pen return opener.open(url, data, timeout) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open response = self._open(req, data) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _ope n '_open', req) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _cal l_chain result = func(*args) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in htt ps_open context=self._context, check_hostname=self._check_hostname) ###該当のソースコード from urllib.request import urlopen from bs4 import BeautifulSoup html = urlopen("https://en.wikipedia.org/wiki/Kevin_Bacon") soup = BeautifulSoup(html, "html.parser") for link in soup.findAll("a"): if 'href' in link.attrs: print(link.attrs['href']) ###試したこと とりあえず進めて見たり、pip3 install urllibなど試しました。 ###補足情報(言語/FW/ツール等のバージョンなど) Python 3.6.5 macです。
回答1件
あなたの回答
tips
プレビュー