user5831134
user5831134

Reputation:

Python selenium string to int

I've tried most of the examples on stackoverflow but I can't find a way. I have two questions, how do I make a string into a text..

posts = driver.find_elements_by_class_name("currency-chaos")
numberOfItems = 1
for post in posts:
    numberOfItems = numberOfItems + 1
    print(numberOfItems)
    print(post.text)

and how do I remove a letter from the text, then transfer it into an int?

Upvotes: 1

Views: 877

Answers (1)

Florent B.
Florent B.

Reputation: 42528

You could use a regular expression to remove the non digit characters and then parse the number with float :

import re

value = float(re.sub(r"[^\d.]", "", post.text))
print("value: %s" % value)

Upvotes: 1

Related Questions