IAmYourFaja
IAmYourFaja

Reputation: 56904

Jsoup selectors with wildcards

I am trying to use JSoup to select some text from an HTML document.

The HTML I'm interested in is a part of a form:

<input type="text" name="key_12345" value="fizz" id="varz_key_12345" class="inline-edit-field">
<input type="text" name="key_28382" value="buzz" id="varz_key_28382" class="inline-edit-field">
<input type="text" name="key_83838" value="foo" id="varz_key_83838" class="inline-edit-field">
<input type="text" name="key_98383" value="bar" id="doekfeokf" class="inline-edit-field">
<input type="text" name="key_19283" value="widget" id="vars_key_19283" class="inline-edit-field">
...etc.

I'm interested in obtaining any <input> element whose id attribute begins with varz_key_. Hence in the example above, I'd be interested in all the inputs except the 4th because its ID doesn't start with varz_key_.

The best I've been able to come up with is:

Document doc = Jsoup.parse(getHtml());
Elements planVarInputs = doc.select("input[id^=\"varz_key_\"]");
log.info("planVarInputs's size is ${planVarInputs.size()}");
for(Element input : planVarInputs) {
    System.out.println(input.ownText());
}

But this gives me the following output:

planVarInputs's size is 0

Any ideas?

Upvotes: 1

Views: 2084

Answers (1)

Joseph Helfert
Joseph Helfert

Reputation: 421

I dont think you need the quotes for jsoup. http://jsoup.org/cookbook/extracting-data/selector-syntax

Upvotes: 2

Related Questions