Hello, so I am working with WWW::Mechanize to submit form and get class schedule and I have extracted the part of HTML I am interested in. My problem is now I want to put the data in the hash table and I don't know where to start. Following is the code I have so far, and I print it out to file just to test if it returns correct data

use WWW::Mechanize qw(); use IO::Socket::SSL qw(); use HTML::TreeBuilder; use 5.10.0; use strict; use warnings; my $mech = WWW::Mechanize->new(ssl_opts => { SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE, verify_hostname => 0, }); my $url = "scheduleurl"; $mech->get($url); my $filename = 'out.htm'; my $result = $mech->submit_form( form_number => 2, fields => { "ctl00\$ContentPlaceHolder1\$TermDDL" => 2171, "ctl00\$ContentPlaceHolder1\$ClassSubject" => 'CS', } ,button => "ctl00\$ContentPlaceHolder1\$SearchButton" ); $mech->submit(); #print $result->content(); open(my $fhandle, '>', $filename) or die "Could not open file '$filena +me' $!"; my $tree = HTML::TreeBuilder->new_from_content($result->content); if (my $div = $tree->look_down(_tag => "div", id => "class_list")){ #print $div->as_text(), "\n"; # say $fhandle $div->as_HTML(),"\n"; my @list = $div->find(_tag => 'ol'); #print Dumper \@list; foreach (@list) { say $fhandle $_->as_HTML(); } } close $fhandle; $tree->delete();

So the script prints this to file I just pasted one item in the list but there are multiple items with the same format.

<ol> <li><span class="ClassTitle"><strong>CS 128</strong></span> Section 01 + <table border="0" cellpadding="5" cellspacing="0" class="GridView" +id="ClassDetails_TBL" width="99%"> <tr> <th align="right" id="TableHeaderCell8" nowrap>Class Nbr</th> <td id="TableCell13">11647</td> <th align="right" id="TableHeaderCell9" nowrap>Capacity</th> <td id="TableCell14">30</td> </tr> <tr> <th align="right" id="TableCell5" nowrap>Title</th> <td class="tablealtstyle" id="TableCell8">Introduction to +C++</td> <th align="right" id="TableCell8a" nowrap>Units</th> <td class="tablealtstyle" id="TableCell9">4</td> </tr> <tr> <th align="right" id="TableCell11" nowrap>Time</th> <td id="TableCell1">3:00 PM&ndash;4:50 PM&nbsp;&nbsp;&nbsp; +TuTh</td> <th align="right" id="TableCell15">Building/Room</th> <td id="TableCell2">8 52</td> </tr> </table> </li> <li></li> ...

so I want to put that data in to the hash table with keys being class titles and values are class information.

{ CS128 Section 01 => { Class Nbr => 11647, Capacity => 30, Title => Introduction to C++, Units => 4, Time => 3:00PM- 4:50PM TuTh, Room => 8 52 } }

In reply to html to hash table by phantom85

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.