get csv data from a website

csv, python, python-3.x

Solution

It depends on what you want to do with the data. If you simply want to download the data you can use urllib2.

import urllib2

downloaded_data  = urllib2.urlopen('http://...')

for line in downloaded_data.readlines():
    print line

If you need to parse the csv you can use the urrlib2 and csv modules.

Python 2.X

import csv
import urllib2

downloaded_data  = urllib2.urlopen('http://...')
csv_data = csv.reader(downloaded_data)

for row in csv_data:
    print row

Python 3.X

import csv
import urllib.request

downloaded_data  = urllib.request.urlopen('http://...')
csv_data = csv.reader(downloaded_data)

for row in csv_data:
    print(row)

Problem

How do I download and read the CSV data on this website using Python: http://earthquake.usgs.gov/earthquakes/feed/csv/1.0/hour

Original source

Related problems