perlmad has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: Parse html file with javascript
by hippo (Archbishop) on May 26, 2016 at 14:07 UTC
    Hot 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

    Start with the documentation.

      the webpage has fully java script, How can i handle this?

        see here. You just have to read a little further…

        the webpage has fully java script, How can i handle this?

        Please quote the FAQ answer to this question