Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hello Monks, I'll be honest, this is my first post here, and I'm fairly new to perl (I come from a PHP background, I'm very excited to start perl!). I've finally found a suitable project to try my (perl) hand at. I'm teaching a lab section of Engineering Computing this semester, and as part of the class, the students are to email me their work (which, so far, consists of excel workbooks). After manually saving 30-some-odd of these today, I said, "There's gotta be a better way". Enter perl. I've been doing some reading on WWW::Mechanize and have successfully implemented it... so far. I'm trying to get it to find all the submitted excel files in my inbox (done), and download them (having trouble with this). Here's what I have so far:
#!C:\perl\bin\perl.exe use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); my $url = 'https://webmail.my_university.edu'; $mech->get($url); # login $mech->submit_form( form_number => 0, fields => { imapuser => 'c4onastick', pass => 'my_password_here', } ); # Navigate back to the first page that contains the most recent messag +es $mech->follow_link(url_regex => qr/page=1/ ); # Find all links (messages) with Lab 2 in the subject my @links = $mech->find_all_links( text_regex => qr/lab\s*2/i ); my $content; foreach my $link (@links) { print $link->url."\n"; print $link->text."\n"; print "Following...\n"; $mech->follow_link( url => $link->url); $mech->follow_link( url_regex => qr/\.xls/i ); #link to the attach +ed excel file $content .= $mech->content; # this might be where it is breaking d +own last; # Jump out after one for testing $mech->back; } mkdir "Eng_files", 0755 or die "Couldn't create directory: $!"; chdir "Eng_files" or die "Can't change directory: $!"; open(FH, ">", "test.xls"); print "Writing out...\n"; print FH $content; print "Done.\n\n";
So far, it works, it writes out and everyone is happy, except excel. It wont let me open them (I get a funky ready-only error, I don't think its excel's fault, I think I'm doing something wrong in the perl above). I'll eventually save these with the student's name in the filename (which I can also get from the message), but for now, I need to be able to open them to grade them! Thanks in advance for your help. I really look forward to becoming part of this community! (Next project is a perl script to grade them for me!)

In reply to Downloading Excel Spreadsheets from Web-based Mail by c4onastick

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 surveying the Monastery: (2)
As of 2024-04-25 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found