所以,我正在搞乱urllib.request
在Python 3中,我想知道如何将获取互联网文件的结果写入本地计算机上的文件。我试过这个:
g = urllib.request.urlopen('http://media-mcw.cursecdn.com/3/3f/Beta.png')
with open('test.png', 'b+w') as f:
f.write(g)
但我收到了这个错误:
TypeError: 'HTTPResponse' does not support the buffer interface
我究竟做错了什么?
注:我见过这个问题 https://stackoverflow.com/questions/8116623/how-to-download-a-file-using-python,但它与Python 2有关urllib2
它在 Python 3 中进行了彻底修改。
change
f.write(g)
to
f.write(g.read())
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)