java - JSoup how to store elements in an array? -


i making java program scrapes amazon page. when enters search query , resulting page of results shows up, program takes of resulting prices. know how find these prices , print them console. example, given user searched term "spoon", enter following code:

elements prices = doc.select("span.s-price");     system.out.println("prices: " + prices); 

i receive following output:

prices: <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 7.99</span> <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 4.24</span> <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 12.00</span> <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 9.99</span> <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 22.99</span> <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 10.00</span> <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 5.94</span> <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 4.99</span> <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 4.79</span> <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 5.99</span> <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 15.48</span> <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 4.07</span> <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 5.88</span> <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 12.99</span> <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 6.71</span> <span class="a-size-base a-color-price s-price a-text-bold">cdn$ 11.99</span> 

however, not know how take these strings , store them in array? more 'cdn$ double' values, though think know how might handle issue. how store these strings array?

here code portion of amazon.ca's source code interested in(long , messy, apologies):

<div id="center">   <div id="atfresults" class="a-row s-result-list-parent-container"><ul id="s-results-list-atf" class="s-result-list s-col-1 s-col-ws-1 s-result-list-hgrid s-height-equalized s-list-view s-text-condensed"><li id="result_0" data-asin="b00x08p338" class="s-result-item"><div class="s-item-container"><div class="a-fixed-left-grid"><div class="a-fixed-left-grid-inner" style="padding-left:160px"><div class="a-fixed-left-grid-col a-col-left" style="width:160px;margin-left:-160px;_margin-left:-80px;float:left;"><div class="a-row"><div class="a-column a-span12 a-text-center"><a class="a-link-normal a-text-normal" href="http://www.amazon.ca/hic-harold-cocktail-stainless-12-inch/dp/b00x08p338/ref=sr_1_1?ie=utf8&amp;qid=1436286484&amp;sr=8-1&amp;keywords=spoon"><img alt="product details" src="http://ecx.images-amazon.com/images/i/21tcgyjdh%2bl._aa160_.jpg" onload="viewcompleteimageloaded(this, new date().gettime(), 16, false);" class="s-access-image cfmarker" height="160" width="160"></a></div></div></div><div class="a-fixed-left-grid-col a-col-right" style="padding-left:2%;*width:97.6%;float:left;"><div class="a-row a-spacing-small"><a class="a-link-normal s-access-detail-page  a-text-normal" title="hic harold import bar cocktail mixing spoon, 18/8 stainless steel, 12-inch" href="http://www.amazon.ca/hic-harold-cocktail-stainless-12-inch/dp/b00x08p338/ref=sr_1_1?ie=utf8&amp;qid=1436286484&amp;sr=8-1&amp;keywords=spoon"><h2 class="a-size-medium a-color-null s-inline s-access-title a-text-normal">hic harold import bar cocktail mixing <strong>spoon</strong>, 18/8 stainless steel, 12-inch</h2></a><div class="a-row a-spacing-none"><span class="a-size-small a-color-secondary">by </span><span class="a-size-small a-color-secondary">hic harold import co.</span></div></div><div class="a-row"><div class="a-column a-span7"><div class="a-row a-spacing-none"><a class="a-link-normal a-text-normal" href="http://www.amazon.ca/hic-harold-cocktail-stainless-12-inch/dp/b00x08p338/ref=sr_1_1?ie=utf8&amp;qid=1436286484&amp;sr=8-1&amp;keywords=spoon"><span class="a-size-base a-color-price s-price a-text-bold">cdn$ 7.99</span></a> 

not cleanest solution should work. elements list of element.

    arraylist<element> elements = new arraylist<>();      (element e : prices) {         elements.add(e);     }      element[] elementarr = elements.toarray(new element[]{}); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -