Answer the question
In order to leave comments, you need to log in
How to properly pull out a piece of text using bs4?
Good day
I'm sitting trying to parse a piece of text
<p class="order-quantity j-orders-count-wrapper" data-link="class{merge: selectedNomenclature^ordersCount < 1 toggle='hide'}">Купили
<span data-link="{include tmpl='productCardOrderCount' ^~ordersCount=selectedNomenclature^ordersCount}">
<script type="jsv#29_"></script>
<script type="jsv#27^"></script>
<script type="jsv#30_"></script>
<script type="jsv#26^"></script>более 700 раз<script type="jsv/26^">
</script>
<script type="jsv/30_"></script>
<script type="jsv/27^"></script>
<script type="jsv/29_"></script>
</span>
</p>
Answer the question
In order to leave comments, you need to log in
from bs4 import BeautifulSoup
import re
html = """
<p class="order-quantity j-orders-count-wrapper" data-link="class{merge: selectedNomenclature^ordersCount < 1 toggle='hide'}">Купили
<span data-link="{include tmpl='productCardOrderCount' ^~ordersCount=selectedNomenclature^ordersCount}">
<script type="jsv#29_"></script>
<script type="jsv#27^"></script>
<script type="jsv#30_"></script>
<script type="jsv#26^"></script>более 700 раз<script type="jsv/26^">
</script>
<script type="jsv/30_"></script>
<script type="jsv/27^"></script>
<script type="jsv/29_"></script>
</span>
</p>
"""
soup = BeautifulSoup(html)
full_text = re.sub(' +', ' ',soup.find('p').get_text().strip().replace(u'\n', u' '))
print(full_text)
number = re.findall("[0-9]+",soup.find('p').get_text())
print(nunber)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question