Quote:
Originally Posted by TonytheBookworm
Starson17,
If i wanted an if statement that checked if the parent was <div id='MainContent'>
how would I go about doing it?
would it be
Code:
mydaddy = item.parent
if mydaddy.name = 'MainContent'
.......
|
item and mydaddy are BeautifulSoup Tag objects. Each Tag object has a specified list of properties. mydaddy is the parent of item. The name of mydaddy is 'div'. mydaddy has an attribute called 'id'. The value of that attribute is 'MainContent'.
You can access a tag's attributes by treating the Tag object as though it were a dictionary. Thus you want:
Code:
if mydaddy['id'] == 'MainContent'
.......
or
Code:
if mydaddy.has_key('id') and mydaddy['id'] == 'MainContent'
.......