View Single Post
Old 03-02-2011, 09:25 AM   #12
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 clintiepoo View Post
I spent some time on the code, and I'm just not seeing how to do this. It tags the parent tag with <p> tags, which I get, but my problem (I think) is that I'm grabbing spans and not a div's. These just kind of sit out there inside the body, with no parent tag around them.
HTML is organized as a tree, so all tags have a parent, except the root tag.

Quote:
Is there a way to put what I grab (for example, dict(name='img', attrs={'id':'img-holder'})) and put a tag around that?
You're going to need to look at Beautiful Soup then go back to the code I gave you.

I took a look at your site. The parent of your img tag is the body tag. You can use that tag or play with the next sibling and previous sibling tags. You can't just tell BS to put the img inside another tag. You can create a p tag (with "Tag") and you can put your found img tag inside it, but now it's no longer in your page. It's hanging free and that p tag with the img inside it needs to be put into a tag in the tree forming your page. You'll need to use insert or replaceWith from BS to do that. Study the code I gave you, then study the BS docs at the link above to see how it's done. I suspect you'll come to understand why this is a pain to solve, and that's where we started.

Last edited by Starson17; 03-02-2011 at 09:36 AM.
Starson17 is offline   Reply With Quote