我正在尝试提取一些URL,这些URL可以是一个以上的邮件,它们可以是正文电子邮件中的内容。
我正在尝试使用以下方法解析网址:
use strict;
use warnings;
use Net::IMAP::Simple;
use Email::Simple;
use IO::Socket::SSL;
# here must be the connection to imap hidden for economize space
my $es = Email::Simple->new( join '', @{ $imap->get($i) } );
my $text = $es->body;
print $text;
my $matches = ($text =~/<a[^>]*href="([^"]*)"[^>]*>.*<\/a>/);
print $matches;
在$ text上,我有下一个文本:
--047d7b47229eb3d9f404e58fd90a
Content-Type: text/plain; charset=ISO-8859-1
Try1 <http://www.washingtonpost.com/>
Try2 <http://www.thesun.co.uk/sol/homepage/>
--047d7b47229eb3d9f404e58fd90a
Content-Type: text/html; charset=ISO-8859-1
<div dir="ltr"><a href="http://www.washingtonpost.com/">Try1</a><br><div><br></div><div><a href="http://www.thesun.co.uk/sol/homepage/">Try2</a><br></div></div>
--047d7b47229eb3d9f404e58fd90a--
程序的输出给了我一个1
……。
任何人都可以帮忙吗?
感谢您的建议。
Email :: Simple不适合MIME消息。改用Courriel。正则表达式不适用于HTML解析。使用Web :: Query代替。
use Courriel qw();
use Web::Query qw();
my $email = Courriel->parse( text => join …);
my $html = $email->html_body_part;
my @url = Web::Query->new_from_html($html)->find('a[href]')->attr('href');
__END__
http://www.washingtonpost.com/
http://www.thesun.co.uk/sol/homepage/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句