Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I don't understand the reason behind the various approaches rather than keep things clean and just sticking with the Mojo based solution for everything.

The approaches I was using are ones I understand. First with WWW::Mechanize, which I've used on that site for years. I haven't worked up the facility to do it with Mojo yet, despite many attempts. What happens is that I try to extend the script in a small way and can't quite get there. You said if I ran into the weeds again, let you know, so let's try this one, because it's where I was/am stuck with mojo.

I'm trying to enter the site at the beginning and mechanize my way through to the table I need after the initial sky map has been made. I tried commands like this to tell me something about the page:

$ mojo get https://www.fourmilab.ch/yoursky/ '*' attr id skylat skynsn skynss skylon skyewe skyeww horlat hornsn hornss horlon horewe horeww feedback $

I see 2 of the fields I need to populate here, but I don't know how to deal with the button in the mojo context. In your successful upthread script, you seem not to use a click_button event to get it done, so I tried to squeak by the same way:

$ ./3.mo_scrape.pl ./3.mo_scrape.pl 45.5 -122.4 0.346 Can't call method "children" on an undefined value at ./3.mo_scrape.pl + line 45. $ cat 3.mo_scrape.pl #!/usr/bin/env perl use Mojo::UserAgent; use 5.016; use warnings; use Mojo::UserAgent; use DateTime::Format::Strptime; use open ':std', OUT => ':utf8'; use Mojo::DOM; use Log::Log4perl; # get rid of old log my $file = '/home/hogan/Documents/hogan/logs/4.log4perl.txt'; unlink $file or warn "Could not unlink $file: $!"; my $log_conf4 = "/home/hogan/Documents/hogan/logs/conf_files/4.conf"; Log::Log4perl::init($log_conf4); #info my $logger = Log::Log4perl->get_logger(); $logger->info("$0"); ## important...no trailing zeroes else 301 error my $lat = 45.5; my $long = -122.4; my $elev = .346; #km $logger->info("$lat $long $elev"); my $guess = 2458960; #Earth day 2020 in julian days my $west_long = -$long; # the API docs says you must identify yourself, please make this somet +hing legit # my $name = '(example.com, contact@example.com)'; # can't I pretend to be a browser like any other? my $uaname = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like G +ecko) Chrome/40.0.2214.93 Safari/537.36'; my $ua = Mojo::UserAgent->new; $ua->transactor->name($uaname); my $pturl = 'https://www.fourmilab.ch/yoursky/'; my $tx = $ua->post( $pturl => form => { skylat => $lat, skylon => $west_long +} ); $tx = $ua->post( $pturl => form => { utc => $guess, date => '2' } ); my $sunrow = $tx->res->dom->at('center:nth-of-type(3) table tr:n./2th- +of-type(3)'); # output say 'Name:' . $sunrow->children->[0]->all_text; say 'Altitude: ' . $sunrow->children->[4]->text; say 'Azimuth: ' . $sunrow->children->[5]->text; say 'Visible: ' . $sunrow->children->[6]->text; $

Q1) How do I lose this one? (I'd like to see the equivalent of $mech->uri) If I need the button it would have to look something like submit_button:

%= submit_button 'Ok!', id => 'foo'

Q2) What gives with the %= symbol on the left?

I thought there would be a better, local way to get whatever data you are looking for, but I'm not an astronomer.

I took Stellar Evolution my final semester in physics. I was doing alright until the final turned out to be a computer project that was to integrate a star given a certain composition (no idea what syntax). I was caught completely flatfooted and had somewhat of a meltdown, where I decided to continue my degree with mathematics instead. The failure has stung through the decades.

If Astro::Coord::ECI::Sun does this then I don't see any problem in just calling that as many times as you require.

Copy that.


In reply to Re^4: polishing up a json fetching script for weather data by Aldebaran
in thread polishing up a json fetching script for weather data by Aldebaran

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 pondering the Monastery: (5)
As of 2024-04-19 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found