R
R
Roman Radic2020-07-02 14:00:34
Python
Roman Radic, 2020-07-02 14:00:34

Why are line breaks not removed?

from requests_html import HTMLSession
session = HTMLSession()
resp = session.get(' https://example.com/blog/508180/ ')

description = str(resp.html.xpath('//meta[@name="description "]/@content')).replace('\r\n','')
print(description)


when executing the code it gives: '\r\n\r\ nblhablha
, blhablha, blhablha, blhablha, blhablha,

'
description = str(resp.html.xpath('//meta[@name="description"]/@content')).replace('\r\n' , '')

description = str(resp.html.xpath('//meta[@name="description"]/@content')).lstrip()

description = str(resp.html.xpath('//meta[@name="description"]/@content')).strip()


Still outputs

'\r\n\r\nblhablha, blhablha, blhablha, blhablha, blhablha,'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Radic, 2020-07-02
@user28

The problem was in non-escaped characters, it was necessary like this:

description = str(resp.html.xpath('//meta[@name="description"]/@content')).replace('\\r\\n' , '')

S
soremix, 2020-07-02
@SoreMix

Could not help but leave through the replay, what site is there?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question