Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://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:/ +/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <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>
Output:
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

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 taking refuge in the Monastery: (8)
As of 2024-04-18 06:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found