Beispiel #1
0
 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)
Beispiel #2
0
 def crawlQuery(self):
     self.crawlerObject = cwl.Crawler(self.query)
     self.crawlerObject.writeTextToFile(
         self.crawlerObject.getTextFromWebsite(
             self.crawlerObject.getLibUrl()))
Beispiel #3
0
 def testInit(self):
     query = "python:math:how to use sine"
     c = cw.Crawler(query)
     self.assertEqual(c.query, query)
Beispiel #4
0
 def testGetTextFromWebsite(self):
     query = "python:math:how to use sine"
     c = cw.Crawler(query)
     htmlCode = c.getTextFromWebsite(c.getLibUrl())
     self.assertIs(type(htmlCode), BeautifulSoup)
Beispiel #5
0
 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)
Beispiel #6
0
 def crawlQuery(self):
     self.crawlerObject = cwl.Crawler(self.query)
     lib = self.crawlerObject.getLibUrl()
     text = self.crawlerObject.getTextFromWebsite(lib)
     self.crawlerObject.writeTextToFile(text)