G
G
god_dan632021-11-25 16:41:57
Python
god_dan63, 2021-11-25 16:41:57

How to add an attribute to html tag?

Good afternoon!
I want to add an attribute to the tag, how can I do it using python?

<td class="highlight-grey" colspan="1" data-highlight-colour="grey">\n
            <p><strong>Требование- преемник</strong>
              <br />(возможно несколько значений)</p>
          </td>\n
          <td colspan="4">
            <br /> вместо него надо добавить ссылку
          </td>

You should end up with this:
<td class="highlight-grey" colspan="1" data-highlight-colour="grey">\n
            <p><strong>Требование- преемник</strong>
              <br />(возможно несколько значений)</p>
          </td>\n
          <td colspan="4" class='confluenceTd'> <a href='тут ссылка'>qwe123<a/>
          </td>


I understand how to insert a tag (in my case it's qwe123 ), but how do I change the attribute?
Это -  "<td colspan="4">" превратить в это - "<td colspan="4" class='confluenceTd'>".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-11-25
@god_dan63

soup.find('td', {'colspan': '4'})['class'] = 'confluenceTd'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question