python 下载图片

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 下载图片相关的知识,希望对你有一定的参考价值。

from bs4 import BeautifulSoup
import urllib.request
request=urllib.request.Request(‘https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3193006289,3802606706&fm=26&gp=0.jpg‘)
response=urllib.request.urlopen(request)
data=response.read()
print(data)
with open(‘first_down.jpg‘,‘wb‘) as fp:
    fp.write(data)
    print("download finished")

  在看书的时候有点迷糊。尝试自己弄下。大概步骤是先找到图片的网址。通过urllib解析网址之后得到data数据。 然后通过open函数写道firs_img.jpg文件中。这个是最关键的步骤

以上是关于python 下载图片的主要内容,如果未能解决你的问题,请参考以下文章