I'm trying to extract the text from an h2 tag in HTML through JSoup, but for some reason it's just not working. Any help would be appreciated, thanks!
HTML Code:
<div id="searchTemplate" class="searchTemplate listLayout so_us_en" >
<div id="topDynamicContent">
<div id="s-result-info-bar" class="a-row a-spacing-base searchUndoAUIHacks"><div id="s-result-info-bar-content" class="a-row"><div class="a-column a-span8 a-spacing-none"><div class="s-first-column">
<h2 id="s-result-count" class="a-size-base a-spacing-small a-spacing-top-small a-text-normal">1-16 of 121 results for <span><span class="a-color-state a-text-bold">"rx 390"</span></span></h2></div>
Java Code:
Document doc = Jsoup.connect("https://www.amazon.com/s/ref=nb_sb_ss_c_1_6?url=search-alias%3Daps&field-keywords=rx+390&sprefix=rx+390%2Caps%2C166&crid=2MTUBA4KGNY06").get();
String link= doc.select("div.searchTemplate.listLayout.so_us_en")
.select("div[id= topDynamicContent]")
.select("div.a-row.a-spacing-base.searchUndoAUIHacks")
.select("div.a-row")
.select("div.a-column.a-span8.a-spacing-none")
.select("div.s-first-column")
.select("h2.a-size-base.a-spacing-small.a-spacing-top-small.a-text-normal").first().text();