从字符串中的链接获取网站标题 [英] Getting the website title from a link in a string
本文介绍了从字符串中的链接获取网站标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
字符串:这里是徽章, https://stackoverflow.com/badges bla bla bla"
string: "Here is the badges, https://stackoverflow.com/badges bla bla bla"
如果字符串包含链接(请参见上文),我想解析该链接的网站标题.
If string contatins a link (see above) I want to parse the website title of that link.
它应该返回:徽章-堆栈溢出.
It should return : Badges - Stack Overflow.
我该怎么做?
谢谢.
推荐答案
#!/usr/bin/perl -w
require LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->get('http://search.cpan.org/');
if ($response->is_success) {
print $response->title();
}
else {
die $response->status_line;
}
请参见 LWP :: UserAgent .欢呼声:-)
这篇关于从字符串中的链接获取网站标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文