Perl的HTML :: Selector :: XPath可以用于查找XPath的一般目的吗?

时间:2010-10-17 18:51:40

标签: html css perl

Perl的HTML :: Selector :: XPath可以用于查找XPath的一般用途吗?

  use HTML::Selector::XPath;

  my $selector = HTML::Selector::XPath->new("li#main");
  $selector->to_xpath; # //li[@id='main']

  # functional interface
  use HTML::Selector::XPath 'selector_to_xpath';
  my $xpath = selector_to_xpath('div.foo');

1 个答案:

答案 0 :(得分:3)

HTML::Selector::XPath接受一个CSS选择器并将其转换为等效的XPath表达式。它不允许您在HTML文件中搜索匹配的元素。也许您正在寻找HTML::TreeBuilder::XPathHTML::Query