How to download csv file from website with Python?

There is a website, in that website there is a ‘download data’ button. Once I click this button, a .csv file will be downloaded. How can I write a Python program to do it? Here is the website:

After doing some research,

I now understand the HTTP have Tree structure and I could use request and Beautifulsoup go go through each layer to find what I need. But I have gone through the entire tree structure and I didn’t find where the csv file is stored. Am I in the right direction? Where should I look into to find where the files are stored?

So I ended up pulling the data shown in the webpage (because I can find them in the tree structure). But I want the csv file in the webpage.

I know there are some similar posts but the ones I checked didn’t work. Can someone give me some advice on weather what I am trying to do is correct?


>Solution :

If you inspect what happens if you click that button, you can drop BS4 and get the csv data via urllib3 or requests by getting:

Leave a Reply