Perl 处理 html文件
用perl 读取一个url地址,并获取html代码。
返回的代码格式大致如下。
<html> <body> <table></table> <table> <tr> <td> <table class="pane"> <tr class="pane"> <td colspan="2"></td> </tr> <tr> <td></td> <td>my content1</td> </tr> <tr class="pane"> <td colspan="2"></td> </tr> <tr> <td></td> <td>my content2</td> </tr> </table> </td> </tr> </table></body></html>
<table class="pane"> <tr> <td></td> <td>my content1</td> </tr></table>
use HTML::Element;use HTML::TreeBuilder;$tree = new HTML::TreeBuilder;$tree->parse_file('C:\Users\xxxx\Desktop\CVE\Tool\perl\mergehtml\xxx\1.html');#html file pathforeach my $table ( $tree->find_by_attribute('class','pane') ){ foreach my $td ( $table->find_by_tag_name('td') ) { if($td->as_text()=~/my/)#这里的正则式自己改下 { print $td->as_text()."\n"; } }}