【发布时间】:2014-09-12 14:57:54
【问题描述】:
我一直致力于从 Metacritic 中提取信息,但我现在遇到了无法干净地提取带有撇号或破折号的文本的问题。
以下代码说明了这个问题:
use WWW::Mechanize;
$reviewspage = 'http://www.metacritic.com/movie/a-band-called-death/critic-reviews';
$Review = 'In the end Death triumphs, but its allure and obsession remain a mystery.';
$l = WWW::Mechanize->new();
$l->get($reviewspage);
$k = $l->content;
@Review = $k =~ m{$Review.*?<div class="review_body">(.*?)</div>}s;
print "@Review\n";
输出:
Too much of the doc takes our taste for granted; Alice Cooper, Henry Rollins and others won’t persuade you that Death could have been huge, nor does a clichéd last-act reunion show. But the film’s alternating inquiry — into family love, slow compromise and, yes, death — resonates strongly.
即使网站上的编码是:
<div class="review_body">
Too much of the doc takes our taste for granted; Alice Cooper, Henry Rollins and others won’t persuade you that Death could have been huge, nor does a clichéd last-act reunion show. But the film’s alternating inquiry — into family love, slow compromise and, yes, death — resonates strongly.
</div>
我之前使用 WWW::Mechanize 创建了类似的脚本,但没有一个替换过这样的字符。
【问题讨论】:
标签: perl unicode utf-8 www-mechanize