0

import  requests
from xml import etree
from bs4 import BeautifulSoup
HOST='https://www.muztorg.ru/'
URL='https://www.muztorg.ru/category/studijnye-mikrofony'
HEADERS={
    'accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'user-agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36'
}
def get_html(url,params=''):
    r=requests.get(url,headers=HEADERS,params=params)
    return r
html=get_html(URL)
def get_content(html):
    soup=BeautifulSoup(html,'lxml')
    items=soup.find_all('section', class_='product-thumbnail')
    micerophone=\[\]
    for i in items:
        micerophone.append(
            {
                'name':i.find('div',class_='title').get_text(strip=True),
                'price':i.find('p',class_='price').get_text(strip=True),#тут пытаюсь спарсить цену 5\xa0590р.выдаёт
                'img':HOST+i.find('img').get('data-src')


            }
        )
    return micerophone
print(get_content(html.text))
1
  • imfleisch, проверьте мой ответ :)
    – gil9red
    12 окт 2021 в 13:05

1 ответ 1

0

Я бы сделал функцию, которая из текста оставит только нужное, например только цифры:

def get_number(tag) -> int:
    value = tag.get_text()
    value_int = ''.join(c for c in value if c.isdigit())
    return int(value_int)

Использование при заполнении ключа price:

def get_content(html):
    ...
    for i in items:
        micerophone.append(
            {
                'name':i.find('div',class_='title').get_text(strip=True),
                'price': get_number(i.find('p',class_='price')),
    ...

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.