My program needs to do 2 things.
Extract stuff from a webpage.
Do stuff with a webpage.
However, there are many webpages, su
Put as much of the common stuff together in a single function. Once you've factored as much out as possible, build a mechanism for branching to the appropriate function for each website.
One possible way to do this is with python's if/else
clauses, but if you have many such functions, you may want something more elegant such as
F = __import__('yourproject.facebookmodule')
This lets you put the code that's specific for facebook in it's own area. Since you pass __import__()
a string, you can modify that at runtime based on which site you're accessing, and then just call function F in your generic worker code.
More on that here: http://effbot.org/zone/import-confusion.htm