Download data.zip programmatically for "Loophole-free Bell-inequality violation using electron spins separated by 1.3 kilometres" experiment

Question:

I would like to create a gist or a Jupyter notebook analyzing the data located at Loophole-free Bell-inequality violation using electron spins separated by 1.3 kilometres. The site has this download button

enter image description here

which right-clicking to copy-paste the link tells me it associated with the URL https://data.4tu.nl/ndownloader/files/24056582. If I copy-paste this URL into Firefox it downloads the file. I would like to do this with Python.

I figured I would try making a request to that link with the following.

import requests
requests.get('https://data.4tu.nl/ndownloader/files/24056582')

But the above did not seem to download data.zip as desired. How can I use Python to programmatically download data.zip into the local path of my Python script?

Asked By: Galen

||

Answers:

Try:

import requests

r = requests.get("https://data.4tu.nl/ndownloader/files/24056582")

with open("data.zip", "wb") as f_out:
    f_out.write(r.content)

This downloads the data.zip:

-rw-r--r-- 1 root root 152913 okt 17 00:35 data.zip
Answered By: Andrej Kesely