View Single Post
Old 09-11-2010, 08:47 AM   #2687
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by TonytheBookworm View Post
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'
  .......

Last edited by Starson17; 09-11-2010 at 08:55 AM.
Starson17 is offline