in reply to Re: Grab text from web page using Win32::OLE
in thread Grab text from web page using Win32::OLE

Hi,
Thanks for the link. I had a look at the Win32::IE::Mechanize module but can not find much info apart from the CPAN page. I found people use the following piece of code to e.g. set a field in the page and submit it
$ie->form_name( $name ) $ie->field($name,$value)
However, some initial tests have failed.
I tried to use $name and $field that I found in the source code of the page http://www.nationalrail.co.uk/times_fares/ldb/
<form id="ldb" name="ldb" method="get" action="/times_fares/ldb/;jsess +ionid=10BE7B01E6848F6282BF503A24CD606F" onsubmit="kbSubmit(this)"> <div id="contentbg"> <h1><em>Live</em> Departures &amp; Arrivals</h1> <div class="jpbody"> <p>Please enter the entire, partial name or 3-letter c +ode for your station.</p> <fieldset> <div class="station"> <label for="mainStation">Station:</label> <input id="mainStation" name="mainStation" typ +e="text" value="" size="30"/> <div id="mainStationAc" class="sacDiv"></div>
but it seems that the code snippet
my $url = "http://www.nationalrail.co.uk/ldb/"; $ie = Win32::IE::Mechanize->new( visible => 1 ); $ie->get( $url ); my $formname = "ldb"; my $gotform = $ie->form_name( $formname );
returns an undefined value for $gotform. And, of course, the same applies when I try to set a field, e.g. mainStation to a value.
Furthermore, this is not exactly what I want to do. I want to get the user input when the user submits the form and not set it myself. Is this possible through Win32::IE::Mechanize?

Sorry for so many questions, but I am a total newbie in working with perl + web forms.
Athanasia

Replies are listed 'Best First'.
Re^3: Grab text from web page using Win32::OLE
by athanasia (Pilgrim) on Oct 13, 2008 at 13:19 UTC
    An update on the previous.
    Working with another web page (in.yahoo.com) and adding a sleep 1 after the $ie->get($url) solved the problem of setting a value to a field and submitting the form correctly.
    However, the last question remains. Can I open a browser window through Win32::IE::Mechanize, then let the user type the input (e.g. some text for search) and grab this input in some way through this Perl module?

    Thanks in advance
      I don't know if IE gives access to that. Have you tried it?
        I don't have a clue... I guess your concern is that the browser itself wouldn't let me sneak on the input a user types and submits...?

        If this is the case, is there a workaround?

        The app I need to write should open a browser and navigate the user to a web page. There, the user must create an account by entering username and password. The web page itself will inform them of the success or failure of the account creation.

        Then, I must ask the user to re-type the (approved) username and password in my perl-tk application window. What I try to do is avoid the case that the user enters the wrong credentials in my application. (this is why I want to have the ones from the browser so that I can cross-check and inform them in the case of an error)...