000Z
..snip...
12.95. . .
Essentially, you want to pull all of the SearchResultItem elements out of the document,
and then retrieve the CurrentPrice elements from each of those. For each
SearchResultItem element, you add the CurrentPrice of the object to the total. You also
keep track of the total number of results.
total_price = 0.0
result_count = 0
(hpricot_doc/:SearchResultItem).each do |item| # Iterate through
# each SearchResultItem element
price_element = (item/:CurrentPrice) # Find the CurrentPrice element
# inside of each SearchResultItem element.
if price_element # If it has a price . . .
total_price = total_price + price_element.first.innerHTML.to_f
CHAPTER 6 n TRACKING AUCTIONS WITH EBAY 125
#. . . then pull out the
# inside of the element,
# convert it to a float,
# and add it to the total.
# Note that the method is called innerHTML, but
# actually returns the inside of the element.
# This is because Hpricot was originally an HTML
# parsing library.
Pages:
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188