Formatting the output result using Selenium Python to show text in a single line
Question:
I have the following sample html code, for which I am trying to scrape the data:
<div class="main">
<div class="firstdigitinside">
<span class="firstdigit">
<span class="firstdigithere>1
</span>
</span>
<span class="seconddigit">
<span class="seconddigithere>2
</span>
</span>
<span class="thirddigit">
<span class="thirddigithere>3
</span>
</span>
</div>
</div>
My Code is as Follows:
threedigits = driver.find_element("xpath", ".//div[@class='main']").text
print(threedigits, sep="", end="")
My Output is as follows:
1
2
3
The result I am trying to achieve is supposed to look like this:
123
The output result is supposed to be in a single row without any spaces in between.
Answers:
Try this one
threedigits = ''.join(threedigits.split())
or
threedigits = threedigits.replace('n', '')
I have the following sample html code, for which I am trying to scrape the data:
<div class="main">
<div class="firstdigitinside">
<span class="firstdigit">
<span class="firstdigithere>1
</span>
</span>
<span class="seconddigit">
<span class="seconddigithere>2
</span>
</span>
<span class="thirddigit">
<span class="thirddigithere>3
</span>
</span>
</div>
</div>
My Code is as Follows:
threedigits = driver.find_element("xpath", ".//div[@class='main']").text
print(threedigits, sep="", end="")
My Output is as follows:
1
2
3
The result I am trying to achieve is supposed to look like this:
123
The output result is supposed to be in a single row without any spaces in between.
Try this one
threedigits = ''.join(threedigits.split())
or
threedigits = threedigits.replace('n', '')