3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CSS SelectorをXPathに変換するコマンド

Posted at

XPath書けないけれど、ライブラリの制約などの理由でXPathを書かざるを得ないときはたまにあると思う。そういうときはこのコマンドでCSS SelectorをXPathに変換すると便利。

selector2xpath
# /usr/bin/env perl
# Usage: selector2xpath <CSS Selector>

use strict;
use warnings;
use HTML::Selector::XPath 'selector_to_xpath';

my $selector = shift || exit;
print selector_to_xpath($selector), "\n";

これのPerlスクリプトをパスの通った場所に selector2xpath と名前を付けて保存して、実行権限を与えて source ~/.(zsh|bash)rc すれば終了。
なお、HTML::Selector::XPathが入っていない場合はCPANから入れる必要あり。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?