Tuesday, 27 August 2013

Encoding::UndefinedConversionError: U+00A0 from UTF-8 to US-ASCII

Encoding::UndefinedConversionError: U+00A0 from UTF-8 to US-ASCII

I'm trying to scrap the 52 between the anchor links:
<div class="zg_usedPrice">
<a href="http://rads.stackoverflow.com/amzn/click/B000O3GCFU">52&nbsp;new</a>
</div>
With this code:
def self.parse_products
product_hash = {}
product = @data.css('#zg_centerListWrapper')
product.css('.zg_itemImmersion').each do | product |
product_name = product.css('.zg_title a').text
product_used_price_status = product.css('.zg_usedPrice >
a').text[/(\D+)/]
product_hash[:product] ||= []
product_hash[:product] << { :name => product_name,
:used_status =>
product_used_price_status }
end
product_hash
end
But I think the
http://www.amazon.com/gp/offer-listing/B000O3GCFU/ref=zg_bs_baby-products_price?ie=UTF8&condition=new
part in the URL is producing the following error:
Encoding::UndefinedConversionError:
U+00A0 from UTF-8 to US-ASCII
# ./parser_spec.rb:175:in `block (2 levels) in <top (required)>'
I tried what they suggested in this question. But I'm still getting the
same problem. Is there any workaround for that?
EDIT:
Full error trace:
1) Product (Baby) should return correct keys
Failure/Error: expect(product_hash[:product]["Pet Supplies"].keys).to
eq(["Birds", "Cats", "Dogs", "Fish & Aquatic Pets", "Horses",
"Insects", "Reptiles & Amphibians", "Small Animals"])
TypeError:
can't convert String into Integer
# ./parser_spec.rb:179:in `[]'
# ./parser_spec.rb:179:in `block (2 levels) in <top (required)>'
2) Product (Baby) should return correct values
Failure/Error: expect(product_hash[:product]["Pet
Supplies"].values).to eq([16281, 245512, 513926, 46811, 14805, 364,
5816, 19769])
TypeError:
can't convert String into Integer
# ./parser_spec.rb:183:in `[]'
# ./parser_spec.rb:183:in `block (2 levels) in <top (required)>'
3) Product (Baby) should return correct hash
Failure/Error: expect(product_hash[:product]).to eq({"Pet
Supplies"=>{"Birds"=>16281, "Cats"=>245512, "Dogs"=>513926, "Fish &
Aquatic Pets"=>46811, "Horses"=>14805, "Insects"=>364, "Reptiles &
Amphibians"=>5816, "Small Animals"=>19769}})
Encoding::UndefinedConversionError:
U+00A0 from UTF-8 to US-ASCII
# ./parser_spec.rb:187:in `block (2 levels) in <top (required)>'

No comments:

Post a Comment