[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: OK, stock quotes are doable ... but I may need help with REGEX
In message <35B26301.D1807C6@cyberis.net>, lyoder@cyberis.net writes:
>lynx -dump http://quote.yahoo.com/q?s=COSFF,NSCP
>
>We get the quotes in text format here, but in the middle of a bunch of
>garbage. I don't know much about regular expressions, but I assume that
>would be the easiest way to extract these things. Here's the output.
>Someone wanna give it a go??? I think I'll write this program in Perl
>(I already started with some structure/declaractions).
A simple script follows that will do some of what you want. It's based
on the ideal that yahoo won't change their format, so if they do it
isn't going to work anymore...but that's probably true of most things. :)
I kludged the regexp on the stock quote line so it breaks the data up
by two-or-more-spaces. This section will want to be replaced by a real
regexp that is more intelligent about what it's trying to collect,
depending on what information you want and what you plan to do with it...
Anyway, this should be a good start. Let me know if you have any questions.
(I'll be out of town and out of touch for 7ish days, though.)
#!/usr/bin/perl
open(QUOTE,"lynx -dump http://quote.yahoo.com/q\?s=COSFF,NSCP |") or
die("Can't get quote: $!");
@stocks = grep {/^\[/} <QUOTE>;
close(QUOTE);
for (@stocks) {
chomp;
# do whatever you want with the stock line, from here.....
# a sample, *very simple* and kludgy solution given here
# print "stock line is $_\n";
($name, $date, $price, $change, $changepercent, $volume) =
split(/\s{2,}/);
# this split is a kludge. it will work 'most' of the time...
print "Name is $name, date is $date, price is $price, change is $change\n";
print "Changepercent is $changepercent, Volume is $volume\n";
}