def choose_parser(self, path, html): def open_website(path): if re.match('(?=http)\w+', path): f = urllib2.urlopen(path) else: f = open(path, 'r') return f.read() if path: self.html = open_website(path) if 'on AOL Answers' in self.html: print 'aol' import aol_answers as p elif '- Yahoo! Answers\">' in self.html: print 'yahoo' import yahoo_answers as p elif 'Ask.com' in self.html: print 'ask' import ask_answers as p elif 'Search Askville' in self.html: print 'askville' import askville_answers as p else: raise ParserError('\nError: could not recognize site') return p.parseQAPage(self.html, self.path, self.verbose)
def runTest(self): if 'http://aolanswers.com' in self.url: self.checkQuestionAndAnswer(aol_answers.parseQAPage(urllib2.urlopen(self.url).read(), '', False)) if 'http://answers.yahoo.com' in self.url: self.checkQuestionAndAnswer(yahoo_answers.parseQAPage(urllib2.urlopen(self.url).read(), '', False)) if 'http://answers.ask.com/' in self.url: self.checkQuestionAndAnswer(ask_answers.parseQAPage(urllib2.urlopen(self.url).read(), '', False)) if 'http://askville.amazon.com/' in self.url: self.checkQuestionAndAnswer(askville_answers.parseQAPage(urllib2.urlopen(self.url).read(), '', False))