1

I am trying to find all the input values of a url, but I need to exclude a couple. How do you exclude two or more id's in the list? Similar to this:

        Elements e = doc.select("input[id != fm-login-id]");

but I want to exclude two id's, so I'm looking for something like this:

        Elements e = doc.select("input[id != fm-login-id && id fm-login-password]");

Does anyone know the proper way to do this? Thanks

sandra burgle
  • 47
  • 1
  • 8

1 Answers1

1

I don't know if jsoup actually supports [attr!=value] selectors (they are part of jQuery, and I don't know how much jsoup borrows from it aside from :has()), but in standard selector syntax you do this with :not(), and either ID selectors or attribute selectors depending on your preference:

Elements e = doc.select("input:not(#fm-login-id):not(#fm-login-password)");
Elements e = doc.select("input:not([id=fm-login-id]):not([id=fm-login-password])");
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • Hi, thanks for the help! Do you know if there is a way to parse all the "value" attributes from this elements list? Using `System.out.print(e.attr("value"));` only gives one value from the first element. Does this mean I have to create an array? – sandra burgle Nov 06 '17 at 04:32
  • @sandra burgle: You will need to loop through e (which itself is an array) with `for (Element element : e)`. – BoltClock Nov 06 '17 at 04:34
  • Thanks for help again! [this](https://stackoverflow.com/questions/6128984/how-do-i-make-an-array-from-jsoup-elements-java)(and [this](https://stackoverflow.com/questions/409784/whats-the-simplest-way-to-print-a-java-array)) is what I found after I read your comment. Works great, for anybody who has same problem. – sandra burgle Nov 06 '17 at 04:59