0

I'm trying to figure out how to download/save a .doc file from the internet to somewhere on my computer.

I'm familiar with the urllib2 module and .read(), but I haven't figured out how to save a formatted .doc file to a location on my computer. Is this possible?

mjmostachetti
  • 378
  • 1
  • 4
  • 14

1 Answers1

1

Using the requests library, this is how you do it:

r = requests.get(url, stream=True)
if r.status_code == 200:
    with open('document.doc', 'wb') as f:
        for chunk in r.iter_content():
            f.write(chunk)
    f.close()
shaktimaan
  • 11,962
  • 2
  • 29
  • 33