CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
simple stock quote script



Dec 4, 2000, 2:54 PM

Post #1 of 3 (1716 views)
simple stock quote script Can't Post

I am looking for a simple script that will fetch just one stock quote, for my company, and embed the info into my home html page. An example would be like when you go to a finance site and you automatically get the indexes (NYSE,Nasdaq) on the page. I want to be able to do that with my companies stock symbol, ADP. I do not care about high,lows, volume etc, just the current price. I have implemented several prewritten cgi scripts on our site, but have little to no knowledge on how to create them from scratch. I will greatly appreciate any help that is offered. I have seen java/cgi scripts where a user types in the symbol and gets the info, but I want that part to be automatic when the whole page loads.

Bill Flanagan


Dec 7, 2000, 7:02 PM

Post #2 of 3 (1716 views)
Re: simple stock quote script [In reply to] Can't Post

you can just modified the cgi script you mentioned to default the stock quote to the one you want (ie. default the quote and skip the input part).


Dec 8, 2000, 3:30 PM

Post #3 of 3 (1716 views)
Re: simple stock quote script [In reply to] Can't Post

Here is a simple script that should do the trick. Just change the hardcoded ticker in here (altr) to whatever ticker you want. This is basically just using LWP::Simple with a decimal formatted quote from Motley Fool. Note, I chose to do the formatting of the HTML myself here; there are a lot of HTML formatting modules on CPAN you may want to check into as well.

use CGI;
use LWP::Simple;

my $page = new CGI();
print $page->header();
print $page->start_html("Welcome page");
my $ticker = 'altr'; # change this to yours
print "The current price of $ticker is " ,
&GetLatestPrice($ticker) , "\n";
print $page->end_html();

sub GetLatestPrice
my($ticker) = shift | | return;
$ticker = uc($ticker);
my($page)="" .
"detailed.asp?symbols=" .
my $text = &FormatPage(get($page));
if($text =~ /\nPrice.*\n([\d\.]+)/m)
return $1;

sub FormatPage
my($text) = @_;
$text =~ s/\r//mgi;
$text =~ s/<\s*br[^>]*>/\n/mgi;
$text =~ s/<\s*p[^>]*>/\n/mgi;
$text =~ s/<\s*td[^>]*>/\t/mgi;
$text =~ s/<\s*tr[^>]*>/\n/mgi;
$text =~ s/<[^>]*>//mgi;
$text =~ s/\n+/\n/mgi;
return $text;


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives