Hi Monks

I am using www::mechanize module to parse the webpage and get the html content by HTML::TreeBuilder

here is my code

$mech -> get($home_url); print " base is :",$mech->response()->base,"\n\n"; #print " Home page is :",$mech->uri(),"\n\n"; my $parser = HTML::TokeParser->new($mech->content); html_table_parse(); sub html_table_parse { while( my $div =$parser->get_tag('div') ) { my $div_id=$div->get_attr('id'); next unless defined ($div_id) and $div_id eq 'jqxgrid'; my $div_contenttablejqxgrid=$parser->get_tag('div'); my $div_contenttablejqxgrid_id=$div_contenttablejqxgrid +->get_attr('id'); next unless defined ($div_contenttablejqxgrid_id) and $ +div_contenttablejqxgrid_id eq 'contenttablejqxgrid'; my $div_row=$parser->get_tag('div'); my $div_row_id=$div_row->get_attr('role'); next unless defined ($div_row_id) and $div_row_id eq 'r +ow'; my $div_gridcell=$parser->get_tag('div'); my $div_gridcell_id=$div_gridcell->get_attr('role'); next unless defined ($div_gridcell_id) and $div_gridcel +l_id eq 'gridcell'; print "Content is ",$div_gridcell_id->get_text,"\n\n"; } }

The problem is there is no div tag 'jqxgrid' and 'contenttablejqxgrid' and 'role' is found in the html content and end of the html content has lot of java script files they are

</script> ^M <script type="text/javascript" src="/js/jqwidgets/jqxcore.js"></s +cript> <script type="text/javascript" src="/js/jqwidgets/jqxdata.js"></s +cript> <script type="text/javascript" src="/js/jqwidgets/jqxbuttons.js"> +</script> <script type="text/javascript" src="/js/jqwidgets/jqxscrollbar.js +"></script> <script type="text/javascript" src="/js/jqwidgets/jqxmenu.js"></s +cript> <script type="text/javascript" src="/js/jqwidgets/jqxlistbox.js"> +</script> <script type="text/javascript" src="/js/jqwidgets/jqxdropdownlist +.js"></script> <script type="text/javascript" src="/js/jqwidgets/jqxcheckbox.js" +></script> <script type="text/javascript" src="/js/jqwidgets/jqxgrid.js"></s +cript> <script type="text/javascript" src="/js/jqwidgets/jqxgrid.sort.js +"></script> <script type="text/javascript" src="/js/jqwidgets/jqxgrid.filter. +js"></script> <script type="text/javascript" src="/js/jqwidgets/jqxgrid.selecti +on.js"></script> <script type="text/javascript" src="/js/jqwidgets/jqxgrid.columns +resize.js"></script> <script type="text/javascript" src="/js/jqwidgets/jqxgrid.pager.j +s"></script> <script type="text/javascript" src="/js/jqwidgets/jqxcalendar.js" +></script> <script type="text/javascript" src="/js/jqwidgets/jqxdatetimeinpu +t.js"></script> <script type="text/javascript" src="/js/jqwidgets/jqxdata.export. +js"></script> <script type="text/javascript" src="/js/jqwidgets/jqxgrid.export. +js"></script> <script type="text/javascript" src="/js/jqwidgets/jqxgrid.sort.js +"></script> <script type="text/javascript" src="/js/auctionQuery.js"></script +> </body>^M </html> </script>

Questions: 1) How to get the div tag element ? , 2) How to work javascript with perl while webpage parsing ?, 3) Is this possible to disable java script ?,

Please help me to find how to proceed with it


In reply to Parse html file with java script by perlmad

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.