我正在使用LWP::UserAgent
,
HTML::Selector::XPath
和
HTML::TreeBuilder::XPath
模块来获取href
一组搜索结果中第一个 YouTube 视频的属性值。
到目前为止,我的代码是:
use LWP::UserAgent;
use HTML::TreeBuilder::XPath;
use HTML::Selector::XPath;
my $ua = LWP::UserAgent->new;
#my $response =..
my $html = "http://www.youtube.com/results?search_query=run+flo+rida";
my $tree = HTML::TreeBuilder::XPath->new;
my $xpath = HTML::Selector::XPath::selector_to_xpath("(//*[@id = 'search-results']/li)[1]/div[2]/h3/a/@href/");
my @nodes = $tree->findnodes($xpath);
print" $nodes[0]";
我不确定我的打印是否不正确,或者其他语法是否错误。截至目前它打印
HTML::TreeBuilder::XPath=HASH(0x1a78250)
当我在找它打印时
/watch?v=JP68g3SYObU
谢谢你的帮助!