matt-rock matt-rock - 6 months ago 17
Ruby Question

How to remove white space from HTML text

How do I remove spaces in my code? If I parse this HTML with Nokogiri:

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


I get the following output:

Kühlungsborner Straße
10


which is not left-justified.

My code is:

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

Answer

please try strip

Example:

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