Christian Read
Christian Read

Reputation: 143

Scrapy: How to get all content HTML without "\n"

Hi I have a problem on getting HTML code without "\n" I tried normalize-space function but it seems that it just getting the first paragraph (Not the whole message)

Here's the code that I am using

response.xpath("normalize-space(//div[@class = 'messageContent'])").extract_first()

URL: https://teslamotorsclub.com/tmc/threads/tesla-tsla-the-investment-world-the-2019-investors-roundtable.139047/


Without Normalize-space

<div> class="sample">\n
<span style="color:red;">Sample Message\n</span</div>

With Normalize-space

Sample Message

What I wanted is to also save the HTML code without "\n"

<div> class="sample">
<span style="color:red;">Sample Message</span</div>

Upvotes: 0

Views: 348

Answers (1)

Tom&#225;š Linhart
Tom&#225;š Linhart

Reputation: 10210

If all you want is to remove the newline character from the output, just do it:

response.xpath("//div[@class = 'messageContent']").extract_first().replace('\n', '')

Upvotes: 1

Related Questions