Python - saving image from url

Is there a way to save the image using urlib or Beautiful Soup?

-Thank

+3
source share
4 answers

Just write the file while reading the data.

Here is a simple example

0
source

Beautiful Soup, , . .

import urllib                                       
url = "http://example.com/file.pdf"
uopen = urllib.urlopen(url)
stream = uopen.read()
file = open('filename','w')
file.write(stream)
file.close()

.

import urllib
urllib.urlretrieve('url', 'filename')

2- .. Ignacio Vazquez-Abrams .

+3

.

def get_file(url):
    file_temp = NamedTemporaryFile()
    file_temp.write(urllib2.urlopen(url).read())
    file_temp.flush()
    return File(file_temp)
0

Source: https://habr.com/ru/post/1777366/


All Articles