Browse Source

Speed up removeUnlikelyCandidates

`.Not` returns a brand new Selection, copied element by element.
jvoisin 2 years ago
parent
commit
347740dce1
1 changed files with 4 additions and 1 deletions
  1. 4 1
      internal/reader/readability/readability.go

+ 4 - 1
internal/reader/readability/readability.go

@@ -137,7 +137,10 @@ func getArticle(topCandidate *candidate, candidates candidateList) string {
 }
 
 func removeUnlikelyCandidates(document *goquery.Document) {
-	document.Find("*").Not("html,body").Each(func(i int, s *goquery.Selection) {
+	document.Find("*").Each(func(i int, s *goquery.Selection) {
+		if s.Length() == 0 || s.Get(0).Data == "html" || s.Get(0).Data == "body" {
+			return
+		}
 		class, _ := s.Attr("class")
 		id, _ := s.Attr("id")
 		str := class + id