Skip to content

Instantly share code, notes, and snippets.

@aileron
Last active December 6, 2022 04:21
Show Gist options
  • Select an option

  • Save aileron/a3f6f016e6b0a3d59625ffa265fb6783 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown
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