Quote:
Originally Posted by TonytheBookworm
Been looking at the AventureGamer code and I have a few questions.
|
You got direct answers from the expert/author, but I'll add a bit. I learned about multipage by studying the same AdventureGamer recipe.
Spoiler:
Quote:
Code:
for item in soup.findAll(style=True):
del item['style']
why is the above used? It appears to remove all instance of style but why is it needed?
|
I think of it as optional, but preferable to start with a clean base and then apply styles with the extra CSS. It makes your recipes more consistent. You're right, though, sometimes there can be style info that you may want to preserve
Quote:
Code:
self.append_page(soup, soup.body, 3)
I'm not really clear on this. It appears to me that you are taking the whole soup. appending to the body of the soup with a position of 3?
|
Have you noticed how cool this is? append_page is recursive! It's calling itself. At this point, it's being called to start the append at position 3 (after the basic html, head and body tags), but when it calls itself, it's appending the next page at a different point, not at 3, but where
Code:
newpos = len(texttag.contents)
Quote:
Code:
pager = soup.find('div',attrs={'class':'toolbar_fat'})
if pager:
pager.extract()
I looked in the code and didn't see why the extraction of this is needed. Because the navigation appears to be inside toolbar_fat_next
|
Without answering your question, let me tell you that extract() confused me when I first ran into it, so I'll just give you a reminder of what it does. If "pager" identifies a tag (and all child tags) in "soup," then extracting it gives you two totally separate and disentangled soups. The first is the original soup, without any connection to what was in pager, and the second is pager, without any connection to what was in soup. You can use them for whatever you want. extract() can be used to to delete stuff from soup, or to give you a cleaned up pager, which you may want to use on its own.