philss / floki

Floki is a simple HTML parser that enables search for nodes using CSS selectors.
https://hex.pm/packages/floki
MIT License
2.07k stars 156 forks source link

Cannot search with multiple selectors #18

Closed sllvn closed 9 years ago

sllvn commented 9 years ago

With @html markup from test/floki_test.exs:

<html>
<head>
<title>Test</title>
</head>
<body>
  <div class="content">
    <a href="http://google.com" class="js-google js-cool">Google</a>
    <a href="http://elixir-lang.org" class="js-elixir js-cool">Elixir lang</a>
    <a href="http://java.com" class="js-java">Java</a>
  </div>
</body>
</html>

I am trying to search for an element with multiple classes (on the same element) with the selector .js-cool.js-elixir but Floki is not finding them. However, if I add a space between the classes, as if the second was a descendent of the first, .js-cool .js-elixir, it does return what I'm looking for but should not (as js-elixir is not descendent of js-cool).

Test demonstrating the error:

test "find elements with given multiple classes" do
  class_selector = ".js-cool.js-elixir"

  assert Floki.find(@html, class_selector) == [
    {"a", [
        {"href", "http://elixir-lang.org"},
        {"class", "js-elixir js-cool"}],
      ["Elixir lang"]}
  ]
end
philss commented 9 years ago

@licyeus Please check the new released version "0.4.0". It provides this selector and much more.

sllvn commented 9 years ago

Thanks much :fireworks:; looking at diffs looks to cover my use cases. However, I'm running into errors compiling 0.4. Created #25 for that.