Re: [問題] 請問字串比對問題

看板Perl作者 (c9s)時間16年前 (2009/06/11 10:41), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
用 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)
文章代碼(AID): #1AC6xl_6 (Perl)
文章代碼(AID): #1AC6xl_6 (Perl)