My CSS is better than my xpath—if yours is too…

Monday, 15 March 2010

Each must be one line; tcsh quoting shown.

Install HTML::Selector::XPath.

cpan -i HTML::Selector::XPath

Then go crazy-

perl -MHTML::Selector::XPath -le 'print HTML::Selector::XPath->new("a[rel]")->to_xpath'


//a[@rel]
perl -MHTML::Selector::XPath -le 'print HTML::Selector::XPath->new("#content div > ul.links > a")->to_xpath'


//*[@id='content']//div/ul[contains(concat(' ', @class, ' '), ' links ')]/a

All purpose–

perl -MHTML::Selector::XPath -le 'print HTML::Selector::XPath->new(+shift)->to_xpath' 'body>ol>li>ul>li>b'


//body/ol/li/ul/li/b
1 comment · Commenting is closed
digg stumbleupon del.icio.us reddit Fark Technorati Faves

Discussion

Comments


Sid Burn

Re: My CSS is better than my xpath—if yours is too…

You can also use "HTML::Query" if you want to use CSS Syntax on HTML Documents.

By Sid Burn on 16 March 2010 · 12:05