Need to get the correct URL from the web page

the URL of below:

http://bet.hkjc.com/racing/pages/odds_wp.aspx?date=04-10-2015&venue=st&raceno=10&lang=en  will return the odds for a given race. however there is this drop down list that you can choose to display the odds of "Pre-sell Odds" from "Current Odds".

by default if I use a perl program with above url (via using LWP module), I can get hold of odds of Current Odds,  however, I need the URL to get hold of Odds from Pre-Sell Odds.

So you answer to this question should be a URL that contain the variable to switch "Current Odds" to "Pre-Sell Odds".

The attached perl is able to generate text file from URL of latest Odds for a given race#

perl GenODDS_file.pl ST 20151004 1

(please beware that in Hong Kong ST refer to racecourse of Shatin and HV refer to Happy Valley )

Thank you,

David


Perl program

#!/usr/bin/perl

use strict;
use warnings;
use LWP::Simple;
use POSIX 'strftime';
use Cwd;
use Time::Piece;

no warnings;

my $argument_count = scalar @ARGV;
if ( $argument_count ne 4  ) {
    print "Usage: $0 [ ST | HV ]  [ YYYYMMDD ] [ 1 | 2 ... ] [ sleep_sec ]\n";
    exit;
}

my $raceplace = $ARGV[0];
my $racedate = $ARGV[1];
my $raceno = $ARGV[2];
my $sleep_n_sec = $ARGV[3];

my $true_race_date = Time::Piece->strptime($racedate, "%Y%m%d");
my $yyyy = substr( $racedate,0,4);
my $mm = substr( $racedate,4,2);
my $dd = substr( $racedate,6,2);
my $web_race_date = $dd."-".$mm."-".$yyyy;

while (1) {
   my $mytime = strftime '%Y%m%d%H%M%S', localtime;
   my $data_file = "odds-data\\".$raceplace.$racedate."_".$raceno."_ODDS_WP_".$mytime.".txt";

   open FILE, "> ".$data_file or die $!;
   my $main_url = "http://bet.hkjc.com/racing/pages/odds_wp.aspx?date=".$web_race_date."&venue=".$raceplace."&raceno=".$raceno;
   my $data = get $main_url;
   print FILE $data;
   #
   my $pool_url = "http://bet.hkjc.com/racing/getXML.aspx?type=pooltot&date=".$web_race_date."&venue=".$raceplace."&raceno=".$raceno;
   my $pool_data = get $pool_url;
   print FILE  $pool_data;
   close (FILE);
   #
   if ( $sleep_n_sec == 0 ) {
      exit;
   }
   else {
      sleep $sleep_n_sec;
   }
}
tindavidAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tindavidAuthor Commented:
A sample text file that contains the odds for "Current Odds", what I needed is text file for "Pre-Sell Odd" ST20151004_1_ODDS_WP_20151004123938.txt
Dave BaldwinFixer of ProblemsCommented:
There is not a separate URL for "Pre-Sell Odds".  It is loaded with a function called AJAX that fetches data from the server and replaces the data in the current page.  The URL is http://bet.hkjc.com/racing/getXML.aspx but unless you can use their AJAX function, it just returns an error.
tindavidAuthor Commented:
There must be a way that:
after the Pre-Sell Order is select,  the URL executed must contain a phrase of "Pre-Sell Order",  I need to get hold of the xml submitted with that phrase to provide that there is no other way to collect te proper URL or XML to extract the data
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Dave BaldwinFixer of ProblemsCommented:
No, there isn't any such thing.  Clicking on Pre-Sell activates JavaScript that ends up at 'refreshOddsDoc' on line 1977 of the source.  'refreshOddsDoc' is probably in one of the external JavaScript files but I don't know which one.
tindavidAuthor Commented:
I have found a solution to extract the pre sell odd in Excel VB using in-memory IE from VBA. the key program code is below: (however if you are able to use the similar method in Perl I will like to do so.)

    url = "http://bet.hkjc.com/racing/pages/odds_wp.aspx?date=" & raceDate & "&venue=" & raceSite & "&raceno=" & raceNo
    'open Internet Explorer in memory, and go to website
    If ie Is Nothing Then
        Set ie = New InternetExplorer
    End If
    'ie.Visible = False
    ie.navigate url
    'Wait until IE is done loading page
    Do While ie.READYSTATE <> READYSTATE_COMPLETE Or ie.Busy = True
        Application.StatusBar = "Trying to go to " & url
        DoEvents
    Loop
   
    ' <option selected="" value="">Current Odds</option>
    ' <option value="pre">Pre-Sell Odds</option>

    Dim CurrentWindow As HTMLWindowProxy
    Set CurrentWindow = ie.document.parentWindow
    Call CurrentWindow.execScript("changeDataType(" & """" & "pre" & """" & ")")

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tindavidAuthor Commented:
Another method of getting data from a build-in table
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.