Shop OBEX P1 Docs P2 Docs Learn Events
How to receive a .CSV file ? — Parallax Forums

How to receive a .CSV file ?

BeanBean Posts: 8,129
edited 2012-07-31 13:16 in Accessories
I am wanting to get the prices of stocks from google.

If I send this request to google http://finance.google.com/finance/historical?q=FB&output=csv
from internet explorer, it will automatically ask where I want to save the file. (This is the stock price of FaceBook).

I'm wondering how this would be handled on the spinneret ? I would guess there is some kind of special header that signifies that a file is being sent, but I don't know for sure.

Does anyone know how the spinneret would handle this ?

Bean

Comments

  • Mike GMike G Posts: 2,702
    edited 2012-07-31 11:02
    Bean, the request/response is handled just like any HTTP GET.

    Spinneret HTTP GET to finance.google.com => 74.125.224.194 port 80
    GET /finance/historical?q=FB&output=csv HTTP/1.1
    Host: finance.google.com
    User-Agent: Wiz5200
    

    The response
    HTTP/1.1 200 OK
    Content-Type: application/vnd.ms-excel
    Set-Cookie: SC=RV=:ED=us; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/finance; domain=.google.com
    Set-Cookie: PREF=ID=df0a4229ac0c7aa4:TM=1343757168:LM=1343757168:S=8dLehc3DpX8bbqZt; expires=Thu, 31-Jul-2014 17:52:48 GMT; path=/; domain=.google.com
    Date: Tue, 31 Jul 2012 17:52:48 GMT
    Expires: Tue, 31 Jul 2012 17:52:48 GMT
    Cache-Control: private, max-age=0
    Content-Disposition: attachment; filename="data.csv"
    X-Content-Type-Options: nosniff
    Transfer-Encoding: chunked
    X-Frame-Options: SAMEORIGIN
    X-XSS-Protection: 1; mode=block
    Server: GSE
    
    ?Date,Open,High,Low,Close,Volume
    30-Jul-12,24.00,24.04,23.03,23.15,29285895
    27-Jul-12,23.19,24.54,22.28,23.70,123098340
    26-Jul-12,27.75,28.23,26.73,26.84,64597378
    25-Jul-12,28.39,29.49,28.08,29.34,17230154
    24-Jul-12,28.82,29.45,28.10,28.45,11539799
    23-Jul-12,28.12,29.00,28.01,28.75,12393864
    20-Jul-12,29.00,29.47,28.72,28.76,11869046
    19-Jul-12,29.41,29.50,28.63,29.00,13685031
    18-Jul-12,28.31,29.29,28.15,29.11,16841779
    17-Jul-12,28.48,28.59,27.15,28.09,30392424
    16-Jul-12,30.50,30.50,28.21,28.24,24672074
    13-Jul-12,31.04,31.07,30.56,30.72,8117346
    12-Jul-12,30.70,31.40,30.60,30.81,11306636
    11-Jul-12,31.48,31.56,30.55,30.97,13027752
    10-Jul-12,32.43,32.48,31.16,31.47,14276996
    9-Jul-12,32.10,32.88,31.99,32.17,17785180
    6-Jul-12,31.44,31.90,31.26,31.73,10949006
    5-Jul-12,31.32,31.62,31.02,31.47,10036688
    3-Jul-12,30.91,31.44,30.80,31.20,8765498
    2-Jul-12,31.25,31.73,30.55,30.77,14131476
    29-Jun-12,31.92,31.99,30.76,31.10,19526823
    28-Jun-12,31.96,32.19,30.90,31.36,17713292
    27-Jun-12,32.46,32.90,31.90,32.23,28599506
    26-Jun-12,32.69,33.44,32.50,33.10,24858611
    25-Jun-12,32.86,33.02,31.55,32.06,24352818
    22-Jun-12,32.41,33.45,32.06,33.05,74833976
    21-Jun-12,31.67,32.50,31.51,31.84,21875228
    20-Jun-12,31.92,31.93,31.15,31.60,15558921
    19-Jun-12,31.54,32.18,30.70,31.91,30848913
    18-Jun-12,29.96,32.08,29.41,31.41,42978209
    15-Jun-12,28.50,30.10,28.35,30.01,43563739
    14-Jun-12,27.65,28.32,27.38,28.29,16854124
    13-Jun-12,27.66,28.10,27.10,27.27,17118672
    12-Jun-12,27.48,27.77,26.96,27.40,15822414
    11-Jun-12,27.18,28.07,26.84,27.00,28225887
    8-Jun-12,26.55,27.76,26.44,27.10,38033420
    7-Jun-12,27.00,27.35,26.15,26.31,26167757
    6-Jun-12,26.07,27.17,25.52,26.81,61487019
    5-Jun-12,26.70,27.76,25.75,25.87,42473262
    4-Jun-12,27.20,27.65,26.44,26.90,35230290
    1-Jun-12,28.89,29.15,27.39,27.72,41855500
    31-May-12,28.54,29.67,26.83,29.60,111639200
    30-May-12,28.70,29.55,27.86,28.19,57267867
    29-May-12,31.48,31.69,28.65,28.84,78060799
    25-May-12,32.90,32.95,31.11,31.91,37189630
    24-May-12,32.95,33.21,31.77,33.03,50275879
    23-May-12,31.37,32.50,31.36,32.00,73721135
    22-May-12,32.61,33.59,30.94,31.00,102053826
    21-May-12,36.53,36.66,33.00,34.03,168309831
    18-May-12,42.05,45.00,38.00,38.23,580587742
    17-May-12,38.00,38.00,38.00,38.00,0
    

    The message body contains the records delimited by 0x0A. Columns delimited by comas. The first column contains the column headers.

    The Content-Disposition: header tells the browser to open the file stream using the application that handles *.csv files.
    Content-Disposition: attachment; filename="data.csv"
    
  • BeanBean Posts: 8,129
    edited 2012-07-31 11:55
    Thanks Mike.

    Bean
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-07-31 12:50
    Mike G wrote:
    The message body contains the records delimited by 0x13 0x10

    I'm sure you meant 0x0D and 0x0A, right?

    -Phil
  • Coder96Coder96 Posts: 42
    edited 2012-07-31 13:06
    On winxp down loading with Firefox give an interesting file. When opening with Object Edit(text editor). It complains that it's unable to open UUTF-8 files. So I open it in Frhed(Hex editor).

    The first 3 bytes are 0xef 0xbb 0xbf. then the data starts.

    The looks like the records delimiters are just 0x0a
  • Mike GMike G Posts: 2,702
    edited 2012-07-31 13:16
    I'm sure you meant 0x0D and 0x0A, right?
    Ooops... updated post

    @Coder96, you're right records are delimited by 0x0A and the file stream starts with a BOM 0xef 0xbb 0xbf.
Sign In or Register to comment.