3131from goose .images .UpgradedImageExtractor import UpgradedImageIExtractor
3232from goose .network import HtmlFetcher
3333
34+
3435class CrawlCandidate (object ):
35-
36+
3637 def __init__ (self , config , url , rawHTML ):
3738 self .config = config
3839 self .url = url
3940 self .rawHTML = rawHTML
4041
4142
42-
4343class Crawler (object ):
44-
44+
4545 def __init__ (self , config ):
4646 self .config = config
4747 self .logPrefix = "crawler:"
48-
48+
4949 def crawl (self , crawlCandidate ):
5050 article = Article ()
51-
51+
5252 parseCandidate = URLHelper .getCleanedUrl (crawlCandidate .url )
5353 rawHtml = self .getHTML (crawlCandidate , parseCandidate )
54-
54+
5555 if rawHtml is None :
5656 return article
57-
57+
5858 doc = self .getDocument (parseCandidate .url , rawHtml )
59-
60-
59+
6160 extractor = self .getExtractor ()
6261 docCleaner = self .getDocCleaner ()
6362 outputFormatter = self .getOutputFormatter ()
64-
63+
6564 # article
6665 article .finalUrl = parseCandidate .url
6766 article .linkhash = parseCandidate .linkhash
@@ -81,7 +80,7 @@ def crawl(self, crawlCandidate):
8180 article .tags = extractor .extractTags (article )
8281 # # before we do any calcs on the body itself let's clean up the document
8382 article .doc = docCleaner .clean (article )
84-
83+
8584 # big stuff
8685 article .topNode = extractor .calculateBestNodeBasedOnClustering (article )
8786 if article .topNode is not None :
@@ -91,43 +90,37 @@ def crawl(self, crawlCandidate):
9190 if self .config .enableImageFetching :
9291 imageExtractor = self .getImageExtractor (article )
9392 article .topImage = imageExtractor .getBestImage (article .rawDoc , article .topNode )
94-
93+
9594 article .topNode = extractor .postExtractionCleanup (article .topNode )
9695 article .cleanedArticleText = outputFormatter .getFormattedText (article .topNode )
97-
96+
9897 return article
99-
98+
10099 def getHTML (self , crawlCandidate , parsingCandidate ):
101100 if crawlCandidate .rawHTML :
102101 return crawlCandidate .rawHTML
103102 else :
104103 # fetch HTML
105104 html = HtmlFetcher ().getHtml (self .config , parsingCandidate .url )
106105 return html
107-
108-
106+
109107 def getImageExtractor (self , article ):
110108 httpClient = None
111109 return UpgradedImageIExtractor (httpClient , article , self .config )
112-
113-
110+
114111 def getOutputFormatter (self ):
115112 return StandardOutputFormatter ()
116-
117-
113+
118114 def getDocCleaner (self ):
119115 return StandardDocumentCleaner ()
120-
121-
116+
122117 def getDocument (self , url , rawHtml ):
123118 doc = Parser .fromstring (rawHtml )
124119 return doc
125-
126-
120+
127121 def getExtractor (self ):
128122 return StandardContentExtractor ()
129-
130-
123+
131124 def releaseResources (self , article ):
132125 directory = self .config .localStoragePath
133126 for fname in os .listdir (directory ):
@@ -137,7 +130,3 @@ def releaseResources(self, article):
137130 except OSError :
138131 # TODO better log handeling
139132 pass
140-
141-
142-
143-
0 commit comments