STRING MANIPULATION IN PYTHON:
I have the following string :'Circa 54.000.000 risultati (0,54 secondi)'
i want to get only the second number(54.000.000) as a float(or int so i can use this value to determinate if it is higher than a given number).
result=wd.find_element_by_id('result-stats') search=result.text.replace("risultati","") search= search.replace("Circa", "") search= search.replace("secondi","")
result is used to take the element from the html and by using .replace i manage to have the following string:'54.000.000 (0,54)'
From there how can i get 54.000.000 as a number?
You can use regex, first you need remove
. and replace
import re s = 'Circa 54.000.000 risultati (0,54 secondi)' s = s.replace(".","").replace(",",".") # s = 'Circa 54000000 risultati (0.54 secondi)' a = re.findall(r'[0-9][0-9,.]+', s) print(a) # ['54000000', '0.54'] num = int(a) # 54000000
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module