Home > Back-end >  Convert string with dollar sign in it to int
Convert string with dollar sign in it to int

Time:02-19

Hi i am working on a projekt where i need to scrape a site and get a int. The problem is that i get the text with a dollar sign how do i convert it to an int from. Is there anything i can do?

import requests
from bs4 import BeautifulSoup

url = "https://coinmarketcap.com/currencies/forus/"

page = requests.get(url)
soup = BeautifulSoup(page.content, "html.parser")
x = soup.find_all("div", class_="priceValue")
print(x[0].text.strip())

CodePudding user response:

Looks as though you don't really need to strip() the text in this case but I've left it in anyway (just in case):

import requests
from bs4 import BeautifulSoup

url = "https://coinmarketcap.com/currencies/forus/"

page = requests.get(url)
soup = BeautifulSoup(page.content, "html.parser")
for x in soup.find_all("div", class_="priceValue"):
    print(x.text.strip()[1:])

Output:

0.000354

However:

Your question mentions converting to int which may not be appropriate as the value appears to be a string representation of a floating point number

CodePudding user response:

dollar sign how do i convert it to an int from

No, because the dollar sign cannot be a number. This will be str

  • Related