tags:

views:

55

answers:

1

Can Perl's HTML::Selector::XPath be used for the general purpose of finding XPaths?

  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');
+3  A: 

HTML::Selector::XPath takes a CSS selector and converts it to an equivalent XPath expression. It doesn't let you search an HTML file for matching elements. Maybe you're looking for HTML::TreeBuilder::XPath or HTML::Query.

cjm