webスクレイピングした内容をSlackで通知する練習をしています.
手始めに,東急田園都市線の運行状況(https://www.tokyu.co.jp/unten2/unten.html)を通知するプログラムを書いたのですが,
jupyter notebookで実行した際には出ないエラーが,PythonのIDLEで実行するとエラーになります.
どうしたらこのエラーを防げるのか,ご教示いただきたく存じます.
Python
1from selenium import webdriver 2from selenium.webdriver.chrome.options import Options 3import slackweb 4 5option=Options() 6option.add_argument('--incognito') 7driver=webdriver.Chrome("/Users/User/Downloads/chromedriver",options=option) 8driver.get("https://www.tokyu.co.jp/unten2/unten.html") 9 10elem_search_content=driver.find_elements_by_class_name("line-info_detail") 11content_text=elem_search_content[2].text 12 13driver.close() 14 15slack = slackweb.Slack(url="<Webhook URL>") 16slack.notify(text=content_text)
エラーは
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1350, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1255, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1301, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1250, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1010, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 950, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1424, in connect
self.sock = self._context.wrap_socket(self.sock,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1040, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/itoukeisuke/Documents/train_info.py", line 16, in <module>
slack.notify(text=content_text)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/slackweb/slackweb.py", line 26, in notify
return self.send(kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/slackweb/slackweb.py", line 35, in send
response = self.opener.open(req, data.encode('utf-8')).read()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 542, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1393, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1353, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)>
あなたの回答
tips
プレビュー