小弟刚学perl,请教各位一个问题!

DeadFire 2005-04-06 11:27:05
下面是一网页表格代码,请问如何取出表中的值,谢谢!

<table border="1" width="100%" id="table1">
<tr>
<td width="364">2001</td>
<td>12</td>
</tr>
<tr>
<td width="364">2002</td>
<td>11</td>
</tr>
<tr>
<td width="364">2003</td>
<td>14</td>
</tr>
</table>
...全文
78 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyzxyz1111 2005-04-06
  • 打赏
  • 举报
回复
1: 如果不是要求很严密,可以用正则表达式
2: 可以用HTML::Parser
3: 用HTML::TreeBuilder
h2plus0 2005-04-06
  • 打赏
  • 举报
回复
perl 自带分析Html的包

DeadFire 2005-04-06
  • 打赏
  • 举报
回复
难道我机子设置有问题,我在试试,非常感谢!
xyzxyz1111 2005-04-06
  • 打赏
  • 举报
回复
???
我运行的没错呀? 虽然也没有出现结果
DeadFire 2005-04-06
  • 打赏
  • 举报
回复
我这样写的:

#!/user/bin/perl;

open (FILE,"table.htm")||die("can not open the file!");
while ($line=<FILE>)
{
print"$line\n";
}
close(FILE);

print "-----------------------------\n";

$text=$line=~/\<td.*?\>(.*?)\<\/td\>/i;
print"$text\n";

运行后报错:Use of uninitialized value in pattern match (m//) at web2txt.pl line 12.

请问是什么问题阿!
xyzxyz1111 2005-04-06
  • 打赏
  • 举报
回复
while(<>){
print "$1\n" if(/\<td.*?\>(.*?)\<\/td\>/i);
}
xyzxyz1111 2005-04-06
  • 打赏
  • 举报
回复
while(<>){
print "$1\n" if(/\<td.*?\>(.*?)\<\/td\>/);
}
DeadFire 2005-04-06
  • 打赏
  • 举报
回复
能不能先用正则表达式写一下上面的,我试了半天都有问题,
xyzxyz1111 2005-04-06
  • 打赏
  • 举报
回复
不用联机也可以,先把提前下载的模块放到指定的地方就可以了.
DeadFire 2005-04-06
  • 打赏
  • 举报
回复
哦,谢谢两位.顺便问一下,模块安装是不是必须联机阿?

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧