Alex
Alex

Reputation: 44325

How to use curl in python and redirect content into file?

In python I am trying to use curl to download an image. I am trying the following command:

subprocess.call(['curl',adress,'>',savename])

in order to download the content and redirect it into a filename. With this I try to mimic the command line command

curl http://my_adress/whatever > test.jpg

However, I get gibberish output (the content of the image) and an error saying

Could not resolve host: >

How to make it right?

Upvotes: 1

Views: 466

Answers (1)

salparadise
salparadise

Reputation: 5805

subprocess.check_call(['curl', address], stdout=open(savename, 'w'))

then whatever points to savename will have your image.

Upvotes: 4

Related Questions