爬取一张图片

import urllib.request #调用函数访问网页

response = urllib.request.urlopen('http://placekitten.com/g/500/700')#response 目标转换成对象

cat_img = response.read()
with open('cat_500_700.jpg','wb')as f: #('标题:cat_500_700.jpg(格式)','wb')
f.write(cat_img)
成功=============== RESTART: C:\Users\小仙女\Desktop\爬虫实战\download.py ===============

response.geturl()#geturl输出地址
'http://placekitten.com/g/500/700'
response.info
<bound method HTTPResponse.info of <http.client.HTTPResponse object at 0x0000020D2AE9D630>>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容