Help us understand the problem. What is going on with this article?

ChromeでXPathを取る・検証する

More than 1 year has passed since last update.

スクレイピングなどで HTML の XPath が必要になることがありますが、Chrome で簡単に取れる・検証する方法があります。

XPath を取る

  • Chrome 上で、XPath を取りたい要素を右クリック、「検証」を選ぶ
  • デベロッパーツール上で該当要素を右クリック、「Copy→Copy XPath」を選ぶ

これでクリップボードに XPath が入ります。

XPath を検証する

  • Chrome で対象のサイトを開く
  • デベロッパーツールからコンソールを開く
  • $x('//div/p/span[@class="hoge"]') などとして XPath を指定し、実行する

これで XPath に対応する要素が取れます。

2018/12/25 追記: Chrome 71 で動作確認しました。

ywindish
いつでも発展途上なWeb系エンジニアです。Ruby, Perl あたりがすき。
http://windish.hatenablog.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした