Skip to content

Instantly share code, notes, and snippets.

@aileron
Last active December 6, 2022 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aileron/a3f6f016e6b0a3d59625ffa265fb6783 to your computer and use it in GitHub Desktop.
Save aileron/a3f6f016e6b0a3d59625ffa265fb6783 to your computer and use it in GitHub Desktop.
require 'nokogiri'
html = <<HTML
<main>
<div>plain div</div>
<div class="test">test</div>
<div class="test">test</div>
</main>
HTML
nokogiri = Nokogiri::HTML(html)
p nokogiri.css("main > div:not([class])")
p nokogiri.xpath("/main/div[not(@class)]")
@aileron
Copy link
Author

aileron commented Dec 6, 2022

css では取れるけど、xpath で指定する方法判らなかった

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment