What is .attrs ?

 tag.attrs['src'] 

Closed due to the fact that the essence of the question is incomprehensible by the participants andreymal , 0xdb , Vladimir Klykov , Misha Saidov , S. Nick January 13 at 19:05 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Appeal to the attrs attribute of an object that is in the variable tag - andreymal
  • what is attrs? I can't find anything in the documentation about it. only about library attrs found - D.Ryksd
  • one
    attrs is the name of the attribute. In itself, it means absolutely nothing - it is just a set of letters. - andreymal
  • one
    By specifying the name of the attribute through a dot, you can pull out the attribute value stored in the object. What value there will be - depends on the object. What object you have is stored in the tag variable - we do not know. If this is your code, then you should know :) - andreymal
  • one
    This does not mean anything. Any object belongs to some type (class). Type (class) necessarily lies in some module. Knowledge of the class used will allow (almost) to unambiguously understand what is stored in the attributes of the object. There are dozens of different modules for working with html, and all of them have their own classes for tags and, therefore, their own values ​​for the attrs attribute. Which module you use and to which class this html tag belongs to you - we don’t know, therefore, we can’t answer anything about the contents of attrs. - andreymal

1 answer 1

HTML tags may have attributes , for example

 <img src="ball.png" title="A big ball"> 

Here the <img> has 2 attributes: src and title .

The src attribute has the value ball.png , the title attribute has the value A big ball .

tag.attrs is a dictionary of all attributes of the tag tag , and

  • keys are attribute names , and
  • key values ​​are attribute values .

And so your

  tag.attrs['src'] 

this is the src attribute value of your tag (stored in the tag variable).

  • one
    Comments are not intended for extended discussion; conversation moved to chat . - Yuriy SPb 4:42 pm