FAQ
I am in the process creating in some queries using a Perl script and
want to run the out put of the perl script against another external
software. As example lets say I have Perl script which takes a query
string cleanup all wild characters and run that against the Google,
Yahoo, Ask etc. How can i interface my Perl script to run queries
against Google etc within my Perl code.

Thanks in advance,
Anu

Search Discussions

  • Jeff Pang at Nov 1, 2007 at 12:29 pm

    -----Original Message-----
    From: newBee <auduwage@gmail.com>
    Sent: Nov 1, 2007 1:32 PM
    To: beginners@perl.org
    Subject: interface Perl script with an external website (Pass Values to a web)

    I am in the process creating in some queries using a Perl script and
    want to run the out put of the perl script against another external
    software. As example lets say I have Perl script which takes a query
    string cleanup all wild characters and run that against the Google,
    Yahoo, Ask etc. How can i interface my Perl script to run queries
    against Google etc within my Perl code.
    Though you can program for those web queries by LWP family (see `perldoc lwpcook`),but it's much simpler to do them by using the modules from CPAN. Searching on cpan with keyword of 'google','yahoo','ask' etc you'll find much useful info.
  • Paul Lalli at Nov 1, 2007 at 12:40 pm

    On Nov 1, 1:32 am, auduw...@gmail.com (newBee) wrote:
    I am in the process creating in some queries using a Perl script and
    want to run the out put of the perl script against another external
    software. As example lets say I have Perl script which takes a query
    string cleanup all wild characters and run that against the Google,
    Yahoo, Ask etc. How can i interface my Perl script to run queries
    against Google etc within my Perl code.
    More than likely, you want the WWW::Mechanize module from the CPAN.
    This will allow you to contact a website, fill out a form (such as a
    search box), click the submit button (via code, obviously, not the
    mouse) and retrieve the results.

    http://search.cpan.org/~petdance/WWW-Mechanize-1.32/lib/WWW/Mechanize.pm

    Paul Lalli
  • newBee at Nov 2, 2007 at 3:06 am

    On Nov 1, 7:39 am, mri...@gmail.com (Paul Lalli) wrote:
    On Nov 1, 1:32 am, auduw...@gmail.com (newBee) wrote:

    I am in the process creating in some queries using a Perl script and
    want to run the out put of the perl script against another external
    software. As example lets say I have Perl script which takes a query
    string cleanup all wild characters and run that against the Google,
    Yahoo, Ask etc. How can i interface my Perl script to run queries
    against Google etc within my Perl code.
    More than likely, you want the WWW::Mechanize module from the CPAN.
    This will allow you to contact a website, fill out a form (such as a
    search box), click the submit button (via code, obviously, not the
    mouse) and retrieve the results.

    http://search.cpan.org/~petdance/WWW-Mechanize-1.32/lib/WWW/Mechanize.pm

    Paul Lalli
    Thanks Paul, I will dig into this and see if I can figure it out. If
    not I might have to shoot you an email if its ok.
  • newBee at Nov 16, 2007 at 12:20 am
    I have the fallowing html code, and in this code segment i want to
    fill the field but the problem is instead of name the field as <field
    name"blabla"/> they use the <input id="blabla"/> tag.
    It will be a great help if someone could guide me on this...

    <div id="treeform" class="treeformWide">
    <form>
    <div id="elementsContainer" class="clearfix">
    <div class="formElement">
    <label for="firstName">Your First Name</label>
    <input id="tree_fn" size="15" type="text">
    </div>
    <div class="formElement">
    <label for="lastName">Your Last Name</label>
    <input id="tree_ln" size="15" type="text">
    </div>
    <div class="formElement"><label for="gender">Your Gender</
    label>
    <select id="tree_gen" name="gender"><option selected="selected"
    value="M">Male</option><option value="F">Female</option></select>
    </div>
    </div>
    <div style="text-align: center; clear: both; padding-top:
    10px;">
    <input name="start" class="p_btn" id="start" value="Get
    Started" onclick="submitInfo();s_objectID='hp_build_tree';return
    false;" type="submit">
    </div>
    </form>
    </div>

    Here is the part of the code segment that I have...

    my $mechObject = WWW::Mechanize->new();
    $mechObject -> get($url);

    $mechObject->form_number(2);
    $mechObject->field("tree_fn", $queryString);
    $mechObject->click();

    when I used the field() function and pass the input id as I am doing
    above code segment, I get an error
    No such field 'tree_fn' at c:/perl/lib/WWW/Mechanize.pm line 1243

    so that tells me I cant treat the input tag as same as the field
    tag...

    Thanks in advance...
    Anu
  • Paul Lalli at Nov 16, 2007 at 3:33 pm

    On Nov 15, 6:52 pm, auduw...@gmail.com (newBee) wrote:
    I have the fallowing html code, and in this code segment i want to
    fill the field but the problem is instead of name the field as <field
    name"blabla"/> they use the <input id="blabla"/> tag.
    It will be a great help if someone could guide me on this...
    id is not a substitute for name. The name attribute is required on
    all input tags other than submit and reset. (http://www.w3.org/TR/
    html401/interact/forms.html#h-17.4) If you pass invalid HTML to the
    module, of course it's not going to do what you want.

    Fix the HTML. If you don't have permissions to fix the HTML, contact
    the person who does.

    Alternatively, you can try retrieving a list of all the inputs and
    looping through them to see which one has the right id. Something
    along these lines (untested):

    my @inputs = $mech->current_form()->inputs();
    for my $input (@inputs) {
    if ($input->{id} eq 'blablah') {
    $input->{value} = "whatever";
    }
    }
    __END__

    Frankly, I have no idea if that would do the right thing when you
    later try to submit the form.

    I stand by my original recommendation - fix the HTML.

    Paul Lalli

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedNov 1, '07 at 5:33a
activeNov 16, '07 at 3:33p
posts6
users3
websiteperl.org

3 users in discussion

newBee: 3 posts Paul Lalli: 2 posts Jeff Pang: 1 post

People

Translate

site design / logo © 2022 Grokbase