作者kornelius (c9s)
看板Perl
标题Re: [问题] 请问字串比对问题
时间Thu Jun 11 10:41:48 2009
用 web::scrapper 吧
use Web::Scraper;
use URI;
my $parser = scraper {
process "td.wuc9", 'price[]' => 'TEXT';
result 'part';
};
my $res = $parser->scrape( URI->new("
http://path/to/host" ) );
use Data::Dumper; warn Dumper( $res );
※ 引述《liyih ()》之铭言:
: ※ 引述《frekohmygod (ㄚ助)》之铭言:
: : <td align=center nowrap class='wuc9'>买进价</td><td align=center nowrap
: : class='wuc9'>卖出价</td><td align=center nowrap class='wuc9'>成交价</td>
: : 上列是我所欲抓取网页的原始码
: : 现在的问题是只能抓取到"买进价"
: : 请问要如何写字串比对才能出现"买进价"
: : "卖出价"
: : "成交价"
: : 这是目前为止的进度, while(<File>=~ m/uc9\'\>(.+?)\</)
: : {
: : print $1."\n";
: : print $2."\n";
: : }
: : 请问哪里出了问题? 谢谢指教~
: 可以试看看用 @matches = ($str =~ m/PATTERN/g) 的方式来全部比对。
: ----------------------------------------------------------------------------
: #!/usr/bin/perl
: use strict;
: use warnings;
: my $str = q{<td align=center nowrap class='wuc9'>买进价</td><td align=center
: nowrap class='wuc9'>卖出价</td><td align=center nowrap class='wuc9'>成交价
: </td>};
: my $pattern = qr/<td.+?>(.+?)<\/td>/;
: my @matches = ($str =~ m/$pattern/g);
: my $i = 0;
: print ++$i, "[$_]\n" foreach (@matches);
--
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.170.180.203
※ 编辑: kornelius 来自: 118.170.180.203 (06/11 10:42)