Using Python to Extract Data from a Website

This post shows the extraction of data from a website.  Specifically, I am extracting daily average rainfall at Altus Dam from the water control website for the Tulsa District of the Corps of Engineers.

The list of monthly charts available for Altus Lake can be seen by selecting the link below.

Monthly Charts for Altus Lake

For this example, I will be extracting data from the January and February 1995 monthly charts.  I will be extracting daily rainfall at the dam, which is the data in the second to last column.

January 1995 data for Altus Lake

February 1995 data for Altus Lake

To perform the needed extraction, I use the BeautifulSoup library.





To test if the code is working, a snip of the January 1995 monthly chart is shown below.





A snip of the text file output is shown below.  Notice that the values being extracted match the values from the website.  Recall that values from the second to last column are being extracted.


Comments

Post a Comment