有勇气的牛排博客

python爬虫通过图片网址保存图片

有勇气的牛排 331 Python 2023-05-18 20:51:54

import requests imgUrl = 'http://img3m0.ddimg.cn/9/25/1674043380-1_b_1.jpg' headers = { 'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Mobile Safari/537.36' } res = requests.get(imgUrl, headers=headers).content print(res) name = '3' with open(name + '.jpg', 'wb') as f: f.write(res)

留言

专栏
文章
加入群聊