matt-rock matt-rock - 8 months ago 67
Ruby Question

Nokogiri remove White Space

how do remove spaces in my Code. If get the following Code parse with Nokogiri, I get the following output

<div class="address-thoroughfare mobile-inline-comma ng-binding">Kühlungsborner Straße


Kühlungsborner Straße

This Output is not left-justified.

My Nokogiri Code:

address_street = page_detail.xpath('//div[@class="address-thoroughfare mobile-inline-comma ng-binding"]').text


strip only removes ASCII whitespace and the output you are getitng here is a Unicode no-break space.

You can use gsub by providing a regex with the character code: address_street.gsub(/\u00a0/, ' ')

You can also use address_street.gsub(/[[:space:]]/, ' ') to remove all Unicode whitespace.

remove whitespace from nokogiri output