Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get csv data from a website [closed]

How do I download and read the CSV data on this website using Python:

http://earthquake.usgs.gov/earthquakes/feed/csv/1.0/hour

like image 356
user2117875 Avatar asked Dec 01 '22 20:12

user2117875


1 Answers

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)
like image 196
eandersson Avatar answered Dec 06 '22 09:12

eandersson