Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
For everyone who has the same problem as me and uses HTML::Treebuilder here is the code that worked for me thanks to ambrus and others
#!perl use strict; use HTML::TreeBuilder::XPath; use Data::Dumper; my $tree = HTML::TreeBuilder::XPath->new(); $tree->store_comments(1); my $html = do { local $/; <DATA> };; $tree->parse( $html ); my @nodes = $tree->findnodes( qw( //tr[@class='Odd'] ) ); for my $subtree ( @nodes ) { my($value) = $subtree-> findnodes( qw( td[1]/script ) ); my $script = join "", $value->content_list; my $other_data = $subtree->findvalue( qw( td[2] ) ); printf "Value: %s\n", $script; printf "Other Data: %s\n", $other_data; } __DATA__ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ +/"> <html lang="en" xmlns=""> <body> <table border="0" cellpadding="4" cellspacing="0" class="DataGrid" wid +th="1000px"> <tr class="Odd"><td><script type="text/javascript">Decode("%31%31%39%2 +e%32%35%33%2e%36%31%2e%31%32%31")</script></td><td>Other Data</td></t +r> <tr class="Even"><td><script type="text/javascript">Decode("%32%30%33% +2e%31%35%36%2e%32%30%37%2e%32%34%39")</script></td><td>Other Data</td +></tr> <tr class="Odd"><td><script type="text/javascript">Decode("%32%32%32%2 +e%36%32%2e%32%30%37%2e%37%30")</script></td><td>Other Data</td></tr> <tr class="Even"><td><script type="text/javascript">Decode("%32%30%32% +2e%31%31%32%2e%31%31%37%2e%39%34")</script></td><td>Other Data</td></ +tr> <tr class="Odd"><td><script type="text/javascript">Decode("%35%38%2e%3 +2%30%2e%32%32%38%2e%32%32")</script></td><td>Other Data</td></tr> <tr class="Even"><td><script type="text/javascript">Decode("%31%31%39% +2e%32%35%33%2e%36%31%2e%31%32%30")</script></td><td>Other Data</td></ +tr> <tr class="Odd"><td><script type="text/javascript">Decode("%32%32%33%2 +e%38%37%2e%31%39%2e%35")</script></td><td>Other Data</td></tr> </table> </body> </html>
Value: Decode("%31%31%39%2e%32%35%33%2e%36%31%2e%31%32%31") Other Data: Other Data Value: Decode("%32%32%32%2e%36%32%2e%32%30%37%2e%37%30") Other Data: Other Data Value: Decode("%35%38%2e%32%30%2e%32%32%38%2e%32%32") Other Data: Other Data Value: Decode("%32%32%33%2e%38%37%2e%31%39%2e%35") Other Data: Other Data

In reply to Re: Extract inline script from an XHTML with XML::Twig by SagaraSouske
in thread Extract inline script from an XHTML with XML::Twig by ambrus

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (7)
    As of 2019-10-16 19:47 GMT
    Find Nodes?
      Voting Booth?