Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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.

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?
[Corion]: choroba: I use spod5, which also has that support, and also implements its own kinda-make stuff
[haukex]: But that module I just linked to assumes that most verbatim blocks are runnable code, I have other modules where that's not the case, so there I just copy-and-paste the synopsis into the author tests...
[haukex]: not the most efficient, but then again, I don't have that many modules on CPAN :-)
[Corion]: haukex: Yes, but if it's only supposed to run on my machine, I can be far more liberal with how I extract the code etc.
[Corion]: haukex: Yes - I see the benefit of using Dist::Zilla for people with 150+ modules on CPAN, but I don't see it for myself, and I'm always put off from contributing to such modules because they require a lot of toolchain setup that I don't want to ...
[Corion]: ... spend time on if I only want to provide a short patch
[haukex]: Corion: Yes exactly, in the author tests I don't worry about portability as much, I also don't list the author tests' dependencies in Makefile.PL
[haukex]: I figure someone who wants to contribute will know how to install the missing modules ;-) Not the nicest way to go but I don't think many people are using my modules yet

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2017-02-27 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (385 votes). Check out past polls.