Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Python

Idiom #102 Load from HTTP GET request into a file

Make an HTTP request with method GET to the URL u, then store the body of the response in the file result.txt. Try to save the data as it arrives if possible, without having all its content in memory at once.

import requests
with open("results.txt", "wb") as fh:
	fh.write(requests.get(u).content)

if you don't have requests library installed, make sure to install the requests library like this: pip install requests
import urllib
filename, headers = urllib.request.urlretrieve(u, 'result.txt')
import std.net.curl;
download(u, "result.txt");

New implementation...
< >
programming-idioms.org