파이썬 질문입니다!!

파이썬 질문입니다!!

QA

파이썬 질문입니다!!

본문



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(',','') )
답변을 작성하시기 전에 로그인 해주세요.
전체 60
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT