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.

Asked By: Aslan

||

Answers:

Try this one

threedigits = ''.join(threedigits.split())

or

threedigits = threedigits.replace('n', '')

Answered By: Hanna
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.