Python 3.6.5 - 使用urlopen和下载内容的问题

时间:2018-05-12 01:39:20

标签: python-3.x urlopen

我对python来说比较新,刚刚开始使用一些网络功能。但似乎无论我做什么,我都无法打开网页(打开网址),并将内容复制到文本文件中。

from urllib.request import urlopen
url = https://en.wikipedia.org/wiki/Main_Page
web_page = urlopen(url)
web_page_bytes = web_page.read()
web_page_text = web_page_bytes.decode('UTF-8')
filename = 'download.html'
html_file = open('download.html', 'w', encoding = 'UTF-8')
html_file.write(web_page_text)

似乎无论我做什么,我都无法打开或下载任何内容。我在编码中做错了什么,或者它可能是软件相关的东西。 (使用MacOS) 任何帮助,将不胜感激。

0 个答案:

没有答案