I’d like to preface my question with an apology – which will make this into a 2 part question….double apology.
I am struggling with JSoup (again) 1st apology for repeatedly asking and not learning well enough yet – so can anyone suggest some reading beyond the usual searches for something that will help me understand how to decipher the DOM each time I try this?
If you are still inclined to help, this time, within the doc returned I have:
<a href="/logitech-logitech-wireless-keyboard-k270-with-long-range-wireless-920-003051/info"><span id="priceProductQA1" class="productPrice">$29.99</span></a>
and I want to grab the href and price “29.99”.
I’ve tried
doc = Jsoup.connect(srchStr).get();
for (Element choices : doc.select("a:has(.productPrice)")){
absHref = choices.attr("abs:href");
String pricetxt = choices.text();
and about 10 other ways to no avail. Any better ideas for me?
Here’s another solution:
Explanation:
spantag because you can easy decide if its the one you need (has a class, whileahas none)spantag since it contains the required urlattr("href")insteadBtw. if you are 100% shure there’s only one of such elements on this website you can replace the for-Loop by
Element element = doc.select("span.productPrice").first();, followed by the other two lines of code.