0

I am getting the text from this HTML with one line:

<label class="product_title"> 
  "TEXT 1" 
  <br> 
  "TEXT2" 
</label>

My code is:

title = amazon.find_element_by_css_selector(
  'div > div > label').get_attribute('innerText')

Current output:

TEXT
TEXT1

Desired output:

TEXT TEXT1

Question

How do I obtain my desired output?

jwpfox
  • 5,124
  • 11
  • 45
  • 42
  • Have a look here https://stackoverflow.com/questions/2780904/removing-unwanted-characters-from-a-string-in-python/ – jwpfox Dec 14 '17 at 11:19
  • Answer below works and i think is easier solution but thanks for link! – Rafał Zając Dec 14 '17 at 11:25
  • It's the same answer. What I am pointing out to you is you should expect your question to be deleted shortly as a duplicate. – jwpfox Dec 14 '17 at 11:27
  • Possible duplicate of [Removing unwanted characters from a string in Python](https://stackoverflow.com/questions/2780904/removing-unwanted-characters-from-a-string-in-python) – jwpfox Dec 14 '17 at 11:27

1 Answers1

0

You can replace the new line character with space as below :

title = amazon.find_element_by_css_selector('div > div > label').get_attribute('innerText').replace("\n", " ")
NarendraR
  • 7,577
  • 10
  • 44
  • 82