Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I found this thread with a google search for "perl WWW::Mechanize radiobutton examples." I always read the ones for perlmonks first and found the links to other sources unhelpful. Using the syntax from above, I was able to use WWW::Mechanize to select a radio button, and supply a text with data that populates a new guess on the time at which the event I'm looking for is to occur. That event, btw, is the conjunction of venus and jupiter, which will happen in somewhere around 2 weeks from the writing of this node (6-18-15). I'm using John Walker's Fourmilab site and perl to determine when this will happen exactly.

Walker's site makes a good guinea pig for WWW::Mechanize for several reasons, but let me name a few. This script will produce the same output in a time-invariant fashion. The html isn't written by a machine that cares nothing for legibility. There's no splash screens, adware, flash videos, or similar pests. One can easily change these values and focus on new astronomic events. My script:

#! /usr/bin/perl use warnings; use strict; use 5.010; use WWW::Mechanize::GZip; use HTML::TableExtract qw(tree); my $site = 'http://www.fourmilab.ch/yoursky/cities.html'; my $mech = 'WWW::Mechanize::GZip'->new; $mech->get($site); $mech->follow_link( text => 'Portland OR' ); my $lub = 2457204.63659; #least upper bound my $glb = 2457207.63659; #greatest lower bound say $mech->dump_forms; $mech->set_fields( qw'date 2'); my $guess = median( $lub, $glb); say "guess is $guess"; $mech->set_fields( jd => $guess ); $mech->click_button(value => "Update"); say $mech->dump_forms; my $te = 'HTML::TableExtract'->new; $te->parse($mech->content); my $table = ($te->tables)[3]; my $table_tree = $table->tree; my $table_text = $table_tree->as_text; say "table text is $table_text"; my $venus = $table_tree->cell(4,1)->as_text; say "say venus is $venus"; my $jupiter = $table_tree->cell(7,1)->as_text; say "say jupiter is $jupiter"; sub median{ my ($upper, $lower) = @_; my $return = ($upper+$lower)/2.0; return $return; }

Output:

POST http://www.fourmilab.ch/cgi-bin/Yoursky [request] <NONAME>=Update (submit) date=0 (radio) [*0/Now|1/Universal time:| +2/Julian day:] utc=2015-06-18 23:44:00 (text) jd=2457192.48889 (text) lat=45°31'5" (text) ns=North (radio) [*North|South] lon=122°40'33" (text) ew=West (radio) [East|*West] coords=on (checkbox) [<UNDEF>/off|*on/Ecliptic +and equator] moonp=on (checkbox) [<UNDEF>/off|*on/Moon and +planets] deep=on (checkbox) [<UNDEF>/off|*on/Deep sky +objects of magnitude] deepm=2.5 (text) consto=on (checkbox) [<UNDEF>/off|*on/Outlines] constn=on (checkbox) [<UNDEF>/off|*on/Names] consta=<UNDEF> (checkbox) [*<UNDEF>/off|on/aligned w +ith horizon?] consts=<UNDEF> (checkbox) [*<UNDEF>/off|on/abbreviat +e?] constb=on (checkbox) [<UNDEF>/off|*on/Boundarie +s Stars: Show stars brighter than magnitude] limag=5.5 (text) starn=on (checkbox) [<UNDEF>/off|*on/Names for + magnitude] starnm=2.0 (text) starb=on (checkbox) [<UNDEF>/off|*on/Bayer/Fla +msteed codes for mag.] starbm=2.5 (text) flip=<UNDEF> (checkbox) [*<UNDEF>/off|on/Invert No +rth and South Image size:] imgsize=640 (text) fontscale=1.0 (text) scheme=0 (option) [*0/Colour|1/Black on whit +e background|2/White on black background|3/Night vision (red)] edump=<UNDEF> (checkbox) [*<UNDEF>/off|-xe/Echo ele +ments] elements= (textarea) guess is 2457206.13659 POST http://www.fourmilab.ch/cgi-bin/Yoursky [request] <NONAME>=Update (submit) date=2 (radio) [0/Now|1/Universal time:|* +2/Julian day:] utc=2015-07-02 15:16:41 (text) jd=2457206.13659 (text) lat=45° (text) ns=North (radio) [*North|South] lon=122° (text) ew=West (radio) [East|*West] coords=on (checkbox) [<UNDEF>/off|*on/Ecliptic +and equator] moonp=on (checkbox) [<UNDEF>/off|*on/Moon and +planets] deep=on (checkbox) [<UNDEF>/off|*on/Deep sky +objects of magnitude] deepm=2.5 (text) consto=on (checkbox) [<UNDEF>/off|*on/Outlines] constn=on (checkbox) [<UNDEF>/off|*on/Names] consta=<UNDEF> (checkbox) [*<UNDEF>/off|on/aligned w +ith horizon?] consts=<UNDEF> (checkbox) [*<UNDEF>/off|on/abbreviat +e?] constb=on (checkbox) [<UNDEF>/off|*on/Boundarie +s Stars: Show stars brighter than magnitude] limag=5.5 (text) starn=on (checkbox) [<UNDEF>/off|*on/Names for + magnitude] starnm=2.0 (text) starb=on (checkbox) [<UNDEF>/off|*on/Bayer/Fla +msteed codes for mag.] starbm=2.5 (text) flip=<UNDEF> (checkbox) [*<UNDEF>/off|on/Invert No +rth and South Image size:] imgsize=640 (text) fontscale=1.0 (text) scheme=0 (option) [*0/Colour|1/Black on whit +e background|2/White on black background|3/Night vision (red)] edump=<UNDEF> (checkbox) [*<UNDEF>/off|-xe/Echo ele +ments] elements= (textarea) table text is  RightAscensionDeclinationDistance(AU)From 45°N 122°W:Al +titudeAzimuthSun6h 45m 22s+23° 1.5'1.01727.248&#8722;96.154UpMercury5 +h 17m 22s+21° 6.7'1.00041.481&#8722;78.217UpVenus9h 39m 50s+14° 20.7' +0.504&#8722;8.079&#8722;119.724SetMoon19h 13m 12s&#8722;17° 26.2'58.8 + ER&#8722;18.65783.705SetMars6h 23m 45s+24° 5.1'2.58531.733&#8722;93. +449UpJupiter9h 38m 6s+15° 1.7'6.094&#8722;7.283&#8722;119.835SetSatur +n15h 49m 5s&#8722;17° 53.4'9.200&#8722;53.265127.849SetUranus1h 15m 5 +1s+7° 19.6'20.14051.60213.737UpNeptune22h 46m 15s&#8722;8° 39.6'29.43 +222.30450.179UpPluto19h 0m 30s&#8722;20° 42.1'31.888&#8722;23.07383.2 +56Set say venus is 9h 39m 50s say jupiter is 9h 38m 6s

I've already thanked the monks who wrote this thread in the form of my upvote, but I'd also like to thank all those who help me indulge my twin hobbies of skywatching and perl.


In reply to Re^4: click radio button with WWW::Mechanize by Aldebaran
in thread click radio button with WWW::Mechanize by Niner710

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 14:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found