How To Extract Text That Is Wrapped In \t And \n In Selenium
I am trying to extract some text from an element and print it in console, however, the text is wrapped in \n and \t as gathered from this JSON file during a GET request. The HTML f
Solution 1:
So if I have a string like this :
s = '\n\t\t\t\n \n HELLO\n \n\n'
I would use the below regex :
\n|\t\|
and using replace
then followed by .strip()
,I would do this :
s = '\n\t\t\t\n \n HELLO\n \n\n'
a = s.replace("\n|\t\| ", ' ').strip()
print(a)
output :
HELLO
Process finished with exit code 0
Solution 2:
You can try:
s.xpath('normalize-space(//span[@class="classname "]/text())')
Post a Comment for "How To Extract Text That Is Wrapped In \t And \n In Selenium"