Как спарсить элемент, находящийся под div при помощи HTMLParser()?
Есть код страницы с ценой, нужный текст находится под тегом div, однако мой код выдаёт число 0, в чём проблема? Заметил, что нужных классов на странице несколько, как получить именно этот класс?
Код страницы:
<div class="price">
::before
"2550"
</div>
Мой парсер:
class ParserLyku(HTMLParser):
def handle_starttag(self, tag, attrs):
if (not self.price_is_found and
'class' not in self._product_info and
tag == 'div'):
attrs = dict(attrs)
if attrs.get('class') == 'price':
self.is_price_field = True
def handle_data(self, data):
if (not self.price_is_found and
self.is_price_field and
'class' not in self._product_info):
self._product_info['price'] = data.strip()
self.price_is_found = True