Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Question about WWW::Mechanize::Firefox

by ssj262 (Initiate)
on Nov 12, 2012 at 10:30 UTC ( #1003406=perlquestion: print w/ replies, xml ) Need Help??
ssj262 has asked for the wisdom of the Perl Monks concerning the following question:

I am a student in biology and have recently started learning perl programming. I have been trying to write a code for my project wherein i need to go to a website search for sequences related to mouse strains and save the data on resulting page in a text file.Earlier i was trying to use Mechanize but then after reading I realized it is not good with javascripts. So i am using WWW::Mechanize::Firefox.

I have added the MozRepl and Firebug addon to firefox. The code seems to run but there is no output at the terminal. I am running it on Ubuntu. I have written the code below. Kindly have a look.

#/usr/bin/perl -w use WWW::Mechanize::Firefox; my $moz = WWW::Mechanize::Firefox->new(); $moz->get($url); $url='http://www.informatics.jax.org/javawi2/servlet/WIFetch?page=snpQ +F'; $form_name1='queryForm'; $strain='availableStrains'; @strvalues=("15","38048","71","25292"); $variation='polymorphismType'; $varvalue='1878510'; $func_class='functionClass'; $funcvalue='1878486'; $output='format'; $outformat='tab'; $moz->get( $url ); $moz->form_name( $form_name1 ); $moz->select($strain,\@strvalues); sleep 1; $moz->click({ xpath => '//*[@value=">>"]' }); $moz->select($variation,$varvalue); $moz->select($func_class,$funcvalue); $moz->set_fields( geneSymname => 'chrnb2' ); $moz->select($output,$outformat); sleep 1; $moz->click_button( value => 'Search' ); ($url2) = $mech -> uri; $content=get($url2); print $content,"\n"; exit;

I have a strong feeling that there is some problem with following part.

$moz->click({ xpath => '//*[@value=">>"]' });

The page source for the above button is:

<INPUT VALUE="&gt;&gt;" onClick="setReference(queryForm.availableStrains, queryForm.referenceStrain);" TYPE="button">

This is my first time on perlmonks and pardon me for such a long question. I am looking forward to replies from fellow monks.

Comment on Question about WWW::Mechanize::Firefox
Select or Download Code
Replies are listed 'Best First'.
Re: Question about WWW::Mechanize::Firefox
by Anonymous Monk on Nov 12, 2012 at 11:06 UTC

    I have been trying to write a code for my project wherein i need to go to a website search for sequences related to mouse strains and save the data on resulting page in a text file.Earlier i was trying to use Mechanize but then after reading I realized it is not good with javascripts. So i am using WWW::Mechanize::Firefox.

    Well, there is more than one INPUT TYPE=Button with a value of ">>"

    A better idea would be to match against onClick attribute

    or complain to whomever programmed that page to add ID's or name's to each button, they have a contact form

    or use some bioperl module to access that page, because data appears available for download and http://www.bioperl.org/wiki/Gbrowse says it uses Gbrowse, surely there must be an interface for scraping Gbrowse already :)

      Thank you for your reply. I checked and first part of the code is working. The problem is with the code below.

      $moz->select($variation,$varvalue); $moz->select($func_class,$funcvalue); $moz->set_fields( geneSymname => 'chrnb2' ); $moz->select($output,$outformat); $moz->submit( $form_name1 );

      For the first part I can see strains being added to the box. But for multiple select, I don't see any action happening on the webpage.

        What does that mean?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1003406]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2015-07-29 18:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (267 votes), past polls