Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert python string into integer without commas in them [duplicate]

I am using beautifulsoup4 to extract prices tag from a website. The code i m using is this

 #price
        try:
            price = soup.find('span',{'id':'actualprice'})
            price_result= str(price.get_text())
            print "Price: ",price_result
        except StandardError as e:
            price_result="Error was {0}".format(e)
            print price_result

The output i m getting is a string with a format with commas in it. e.g. 82,000,00

What i want:

Change the format from string price to integer price without commas in it so that i can use them as values intead of strings in excel

like image 332
Panetta Avatar asked Apr 22 '26 07:04

Panetta


1 Answers

You can do this :

>>> string = '82,000,00'
>>> int(price_result.replace(',', ''))
8200000
like image 104
3kt Avatar answered Apr 23 '26 21:04

3kt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!