perl0101 has asked for the wisdom of the Perl Monks concerning the following question:

foreach $line (<STK>) { ($stock) = split(/ /, $line); $hist = `curl -s "http://ichart.finance.yahoo.com/table.csv?s=$stock +&a=3&b=12&c=2008&d=8&e=5&f=2009&g=d&ignore=.csv" | grep -v Date `; }

I am trying to use download history data from Yahoo!Finance by passing parameters to a url, e.g, starting date and ending date parameters.

In the above code, the expected result is stock data from 03/12/2008 to 08/05/2009. But the actual data returned includes data for all the time, for example, data of the year 1984. I use curl -v option to see the details. The output is included as follows.

* About to connect() to ichart.finance.yahoo.com port 80

* Trying 76.13.114.89... connected

* Connected to ichart.finance.yahoo.com (76.13.114.89) port 80

> GET /table.csv?s=AAPL HTTP/1.1

> User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5

> Host: ichart.finance.yahoo.com

> Accept: */*

From the output above, I find the parameters &a=3&b=12&c=2008&d=8&e=5&f=2009&g=d&ignore=.csv are not in the Get request.

I am new to perl and would like to get feedback from here. Thanks.

  • Comment on How to call curl to make a Get request with parameters from perl ?
  • Download Code

Replies are listed 'Best First'.
Re: How to call curl to make a Get request with parameters from perl ?
by ikegami (Patriarch) on May 19, 2009 at 01:10 UTC
    while (defined(my $line = <STK>)) { # Avoid loading file into mem. chomp($line); # Remove trailing newline my ($stock) = split(/ /, $line); ... }

    Or shorter:

    while (<STK>) { chomp; my ($stock) = split / /; ... }

      Thank you for teaching me. I appreciate your suggestion.

Re: How to call curl to make a Get request with parameters from perl ?
by JavaFan (Canon) on May 19, 2009 at 00:30 UTC
    And you are sure $stock contains exactly AAPL, and not a trailing space, newline or some other character? You don't seem to chomp off the newline when reading the line for instance.

      Thank you. The problem is soloved by trailing space for $stock. I add one more step: $stock =~ s/\s+$//;

      This problem makes me confused a lot. Thank you again.

Re: How to call curl to make a Get request with parameters from perl ?
by Fletch (Bishop) on May 19, 2009 at 03:50 UTC

    Possibly tangentially related: perhaps Finance::YahooQuote would be of interest.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.