python - Help interpreting code snippet -


I am very new to dragon and beautiful soup.

For in the statement, what is the incident ? Is this a square, type, variable?

  for event in soup ('TD, width = 90% "): where, linebreak, what = event. Content [: 3] print where.strip () print what. The first statement is a loop that starts with a one-off () break printed '' done ''   

The HTML document sees that which is 90% width in search of TD elements, the object representing the TD element is associated with the name Event .

The second line is a multi-dimensional The car And can be rewritten in this way:

  where = event. Content [0] linebreak = event content [1] what is = event. [2]  

In other words, this TD removes the content from the tag and gives each element a more meaningful name.

The last line in the loop is to break the loop after only checking the first element Due to not using a loop, the code could be rewritten, which is the maximum .


Comments