M
M
MaxFreedom2020-03-04 20:58:49
Python
MaxFreedom, 2020-03-04 20:58:49

How to remove spaces from price value after receiving data from Python 3.8 parser?

Hey! Who can help with the solution to the problem of removing gaps in the price (2,500). The bottom line is that you want to know the price of a share, but a gap interferes with further work with the data. Tried replace(" ", "") but that doesn't help. I also checked the output data type = "class.str", in theory a string, so everything should work or is this separator not a space, as such? To better understand the question, here is the parser code:

import requests
from bs4 import BeautifulSoup

url = "https://www.finam.ru/profile/moex-akcii/qiwi-plc/?market=1"
HEADERS = {"Accept": "*/*", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.106 Safari/537.36"}

def parse():
    html = requests.get(url, headers=HEADERS)
    if html.status_code == 200:
        soup = BeautifulSoup(html.content, "html.parser")
        text = soup.find("span", id="issuer-profile-informer-last")
        price = text.get_text()
        p = price.replace(" ", "")
        print(p)
    else:
        print("Error")
parse()


The output will be a price like "2 500", but you need to remove the space, can you help?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SKEPTIC, 2020-03-04
@RomanticOS

You're not filling that gap. Copy the space from the console when you have the price displayed in the Python console. And substitute it in replace. The gaps are different.

V
vagano, 2020-03-05
@vagano

Write a regex that matches all non-numeric characters and remove them

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question