class Crawler: """Crawler""" def __init__(self) -> None: self.downloader = Downloader() self.parser = Parser() def scrape(self, keyword: Optional[str] = None) -> bool: """scrape Summary: summary Args: keyword: Optional[str] Returns: {variable}: bool Raises: """ if keyword: html = self.downloader.get_text_from_keyword(keyword) if html: self.parser.print_result_from_parser(html) return True return False def change_url(self): """change_url"""
class ParserTestCase(unittest.TestCase): def setUp(self): self.parser = Parser() with open(FILE_PATH + '/test.html', 'r') as file: self.html = file.read() self.titles = self.parser.parser_titles(self.html) def tearDown(self): pass def test_parser_titles(self): self.assertEqual(20, len(self.titles)) def test_print_result(self): flag = self.parser.print_result(self.titles) self.assertTrue(flag) def test_print_result_from_parser(self): flag = self.parser.print_result_from_parser(self.html) self.assertTrue(flag)