Answer the question
In order to leave comments, you need to log in
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)
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()
Answer the question
In order to leave comments, you need to log in
The problem was in non-escaped characters, it was necessary like this:
description = str(resp.html.xpath('//meta[@name="description"]/@content')).replace('\\r\\n' , '')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question