D
D
Dmitri2020-05-10 19:53:20
Python
Dmitri, 2020-05-10 19:53:20

Python get text inside tag?

<div class="rating-box__active" style="width: 100%">
                                    <div class="rating-box__item rating-box__item_active"></div>
                                    <div class="rating-box__item rating-box__item_active"></div>
                                    <div class="rating-box__item rating-box__item_active"></div>
                                    <div class="rating-box__item rating-box__item_active"></div>
                                    <div class="rating-box__item rating-box__item_active"></div>
                                </div>


There is such a construction, how to get the width value from it?
The answer should be:
100%

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2020-05-10
@dmitriy337

my_div = soup.find('div',class_='rating-box__active').get('style')
  print(my_div)	# Вывод - width: 100%
  print(my_div[7:-1])	# Вывод - 100

The code needs to be inserted into tags, without them Habr ate your example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question