2016-04-21 36 views
2

我已經嘗試了大部分的stackoverflow的例子,但我找不到方法。 我有兩個問題,我怎麼做一個串轉換爲文本..Python的硒字符串到int

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

以及如何從文本中刪除一個字母,然後將它轉移到一個int?

+1

能告訴你什麼是您的電流輸出和期望呢? – alecxe

回答

1

你可以使用正則表達式來刪除非數字字符,然後解析與float數量:

import re 

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