Copy text from website to text/excel file

12,014

Solution 1

You're almost done;

import requests
symbol = "mtgoxUSD"
url = 'http://api.bitcoincharts.com/v1/trades.csv?symbol={}'.format(symbol)
data = requests.get(url)

# dump resulting text to file
with open("trades_{}.csv".format(symbol), "w") as out_f:
    out_f.write(data.text)

Solution 2

Using urllib:

import urllib
f = urllib.urlopen("http://api.bitcoincharts.com/v1/trades.csv?symbol=mtgoxUSD")
print f.read()
Share:
12,014
Daniel Henry
Author by

Daniel Henry

Updated on June 18, 2022

Comments

  • Daniel Henry
    Daniel Henry about 2 years

    I'm trying to create a simple (hopefully) Python script that copies the text from this address:

    http://api.bitcoincharts.com/v1/trades.csv?symbol=mtgoxUSD

    to either a simple text file or an excel spreadsheet.

    I've tried utilising urllib and resquests libraries, but every time I would try and run a very basic script, the shell wouldn't display anything.

    For example,

    import requests
    data = requests.get('http://api.bitcoincharts.com/v1/trades.csv?symbol=mtgoxUSD')
    data.text
    

    Any help would be appreciated. Thank you.

  • Daniel Henry
    Daniel Henry about 11 years
    Thank you! Now on to adding news trades every few hours. :)