|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
response=urllib.request.urlopen('http://placekitten.com/g/500/600').read()
with open('mao.jpg','wb') as f:
f.write(response)
response.geturl()
print(response.info())
Traceback (most recent call last):
File "C:/Users/liu/PycharmProjects/pythonProject1/venv/Scripts/55.py", line 3, in <module>
with open('mao.jpg','wb',encoding='utf-8') as f:
ValueError: binary mode doesn't take an encoding argument
为什么会报错啊1
你代码直接 read() 获取网页源码了,返回 bytes 数据
你 geturl 只能对 urllib 获取的对象进行调用,但是却对 bytes 对象进行调用而导致报错
重新找个变量,赋值,对 urllib 对象进行调用函数即可,参考代码:
- import urllib.request
- response=urllib.request.urlopen('http://placekitten.com/g/500/600')
- data = response.read()
- with open('mao.jpg','wb') as f:
- f.write(data)
- response.geturl()
- print(response.info())
复制代码
|
|