def testWriteTextToFile(self): query = "python:math:how to use sine" c = cw.Crawler(query) c.writeTextToFile(c.getTextFromWebsite(c.getLibUrl())) self.assertTrue( os.path.isfile(c.handler.getSearchFilePath("python", "math.txt"))) file = open(c.handler.getSearchFilePath("python", "math.txt")).read() self.assertTrue("sin" in file and "cos" in file and "<html>" not in file)
def crawlQuery(self): self.crawlerObject = cwl.Crawler(self.query) self.crawlerObject.writeTextToFile( self.crawlerObject.getTextFromWebsite( self.crawlerObject.getLibUrl()))
def testInit(self): query = "python:math:how to use sine" c = cw.Crawler(query) self.assertEqual(c.query, query)
def testGetTextFromWebsite(self): query = "python:math:how to use sine" c = cw.Crawler(query) htmlCode = c.getTextFromWebsite(c.getLibUrl()) self.assertIs(type(htmlCode), BeautifulSoup)
def testGetLibUrl(self): query, libUrl = "python:math:how to use sine", "https://docs.python.org/3/library/math.html" c = cw.Crawler(query) self.assertIs(type(c.getLibUrl()), type(libUrl)) self.assertEqual(c.getLibUrl(), libUrl)
def crawlQuery(self): self.crawlerObject = cwl.Crawler(self.query) lib = self.crawlerObject.getLibUrl() text = self.crawlerObject.getTextFromWebsite(lib) self.crawlerObject.writeTextToFile(text)