파이썬 질문입니다!!

파이썬 질문입니다!!

QA

파이썬 질문입니다!!

답변 2

본문



import requests
from bs4 import BeautifulSoup
from io import StringIO

def return_print(*message):
    io = StringIO()
    print(*message, file=io, end="")
    return io.getvalue()


source = requests.get("https://finance.naver.com/marketindex/").text
soup = BeautifulSoup(source, "html.parser")
hotKeys = soup.select("span.value")

index = 0


while True:
    way = input("1과 2중 고르시오(1:국내에서 해외 / 2:해외에서 국내) : ")
    sum = int(input("금액을 입력하시오(원) : "))

    for key in hotKeys:
        index += 1
        print("US"," : ", key.text,"원/달러")
        b = return_print(key.text)
        if index >= 1:
            break
    c = float(b)

 

ValueError: could not convert string to float: '1,082.50'

와 같은 에러가 계속해서 발생합니다. 부탁드립니다~!

이 질문에 댓글 쓰기 :

답변 2


  c = float(b)
----->   c = float(b.replace(',','') )
답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 60
© SIRSOFT
현재 페이지 제일 처음으로