#!/usr/bin/perl -s # # Written by Stephen Thorley # 12 May 2007 - Baseline V1.1 # Update 1.1 added ability to grap up to 5 stock quotes # # usage: ./getprice.pl "stock code" "stock code" # ie: ./getprice.pl amp cba # # =head1 NAME getprice =head1 DESCRIPTION get last price of stocks from the Australian Stock Exchange =head1 PREREQUISITES This script requires LWP and URI modules =pod OSNAMES any =pod SCRIPT CATEGORIES CPAN =cut use LWP::UserAgent; use URI::URL; # I'm getting a copy of the web page from asx and saving it here.. # could be usefull for later projects $hdrs = new HTTP::Headers(Accept => '*/*', User-Agent => "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0; T312461)"); $url = new URI::URL("http://www.asx.com.au/asx/markets/PriceResults.jsp?method=get&template=F1001&ASXCodes=".$ARGV[0]." ".$ARGV[1]." ".$ARGV[2]." ".$ARGV[3]." ".$ARGV[4]); $req = new HTTP::Request(GET, $url, $hdrs); $ua = new LWP::UserAgent; $resp = $ua -> request($req); if ($resp ->is_success) { open (HFILE,"> 123.htm") || die "could not open file handle links.htm"; printf HFILE $resp->content; close HFILE; } else { print $resp->message; } open (CONFDATA, ' 123.htm') || die "Could not open html file"; while () { $x = 0; while ($ARGV[$x] ne "") { chomp $_; #search for string class..last and return the number after the search as $1 if (m/class..last..(\d+.\d+)/g) { printf "last price ".$ARGV[$x]." = ".$1."\n"; }; $x++; }; } close CONFDATA; # Clean up by deleting the 123.html file `rm 123.htm`; __END__ #start of POD section =head1 NAME getprice =head1 DESCRIPTION get last price of stocks from the Australian Stock Exchange =head1 README get last price of stocks from the Australian Stock Exchange, can take up to 5 command line arguments. =head1 PREREQUISITES This script requires LWP and URI modules =pod OSNAMES any =head1 AUTHOR Stephen Thorley www.thorley.biz =pod SCRIPT CATEGORIES Web =cut