读取不同网页的内容,然后加在一起放入另一个URL

Reading contents of different webpages and adding then together to put into another URL

我在 python 方面并不先进,但它是我所知道的最好的编码语言。我正在做这个有 5 URLS 的挑战,每 10 秒更改一次内容。它们每个都包含部分代码。还有一个验证 link 检查我点击的 url 并检查它是否是正确的代码,如果是它会给我一个代码。因此,为了解决这个问题,我正在编写一个脚本,它将获取 5 个 URL 的所有内容并将它们连接在一起并将其粘贴到验证 link 的 URL 中,然后给我一个我需要的代码。

这是我的代码

import urllib.request

fp1 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/clock-pt1?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D")
mybytes1 = fp1.read()
fp1.close()

fp2 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/clock-pt2?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D")
mybytes2 = fp2.read()
fp2.close()

fp3 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/clock-pt3?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D")
mybytes3 = fp3.read()
fp3.close()

fp4 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/clock-pt4?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D")
mybytes4 = fp4.read()
fp4.close()

fp5 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/clock-pt5?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D")
mybytes5 = fp5.read()
fp5.close()

fp6 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/get-flag?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D&string=" + mybytes1 + mybytes2 + mybytes3 + mybytes4 + mybytes5)
mybytes6 = fp6.read()
fp6.close()

print(mybytes6)

但是我收到一个我不明白的错误。

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 request
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 endheaders
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 connect
server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 401, in wrap_socket
_context=self, _session=session)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 808, in __init__
self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1061, in do_handshake
self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sarvesh/Documents/scriptdis.py", line 3, in <module>
fp1 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/clock-pt1?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D")
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
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 _open
'_open', req)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)>

任何人都可以帮助我了解问题所在吗?

您试图在没有有效证书的情况下打开网站。如果您信任该网站,那么您需要创建一个未经认证的上下文,否则 urllib 将抛出您所看到的错误。

import ssl

# This restores the same behavior as before.
context = ssl._create_unverified_context()
fp1 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/clock-pt1?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D", context=context)