爬虫实战那一课
import urllib.requestresponse = urllib.request.urlopen('http://placekitten.com/g/500/600')
cat_img = response.read()
with open('cat_500/600.jpg', 'wb') as f:
f.write(cat_img)
run后出现以下报错:
Traceback (most recent call last):
File "C:\Users\A\Desktop\新建文件夹\download.py", line 6, in <module>
with open('cat_500/600.jpg', 'wb') as f:
FileNotFoundError: No such file or directory: 'cat_500/600.jpg'
为什么会创建不了新文件啊? import urllib.request
req = urllib.request.Request("http://placekitten.com/g/500/600")
response = urllib.request.urlopen(req)
cat_img = response.read()
with open('cat_500_600.jpg', 'wb') as f:
f.write(cat_img)
页:
[1]