*Brittle* but works right now… exercise for the reader to correlate headers with data or dig deeper or adjust scraping. I would really think that if you’re a TA, GA, or prof or whatever that the university would probably install a crontab for you that would be *much* more robust. Something like–

30 2 * * *  `echo "…SQL statement and math…" | mysql students_db | mail you@your.edu -s "Your cron"`

–would be pretty trivial on the backend for someone I would think. Certainly easier and more likely to keep working than–

#!/usr/bin/env perl use strict; use warnings; use WWW::Mechanize::Firefox; use HTML::TableExtract; # Firefox will be in a different place/name for different architecture +s. my $mech = WWW::Mechanize::Firefox->new( activate => 1, autoclose => 1, launch => "/Applications/Firefox.app/Contents/MacOS/firefox" ); $mech->get("https://webapp4.asu.edu/catalog/Home.ext"); eval { my ( $val,$type ) = $mech->eval_in_page(<<'JS'); jQuery(function($){ // Click the ASU campus+online radio button. $("input[name='typeSelection'][value='C']").click(); }); JS }; die $@ if $@; # Get the desired search result page. $mech->get("https://webapp4.asu.edu/catalog/course?s=MAT&n=243&c=DTPHX +&t=2144&f=INTRT&r=44843"); my @headers = ( qr/ Reserved \s+ Available \s+ Seats /x, qr / Students \s+ Enrolled /x, qr/ Total \s+ Seats \s+ Reserved /x, qr/ Reserved \s+ Until /x, ); my $te = HTML::TableExtract->new( headers => \@headers ); $te->parse($mech->content); for my $row ( $te->rows ) { no warnings "uninitialized"; s/\A\s+//g, s/\s+\z//g, s/\s/ /g for @$row; next unless grep length, @$row; print "Scraped info: ", join(',', @$row), "\n"; }
Scraped info: 10,40,50,n/a

Reading: WWW::Mechanize::Firefox, HTML::TableExtract, jQuery (note, they are using a positively ancient version right now: 1.2.3).


In reply to Re: Downloading a web page over HTTPS? by Your Mother
in thread Downloading a web page over HTTPS? by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.