From 28a061a03f73417756fb1ef4b753dadb4d6281fd Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sat, 5 Feb 2022 16:23:40 -0500 Subject: [PATCH] match all images in hoots --- hoot.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hoot.go b/hoot.go index 7105f69..1b053db 100644 --- a/hoot.go +++ b/hoot.go @@ -44,21 +44,23 @@ func hootextractor(r io.Reader, url string, seen map[string]bool) string { log.Printf("error parsing hoot: %s", err) return url } - divs := tweetsel.MatchAll(root) url = strings.Replace(url, "mobile.twitter.com", "twitter.com", -1) - - var wanted string wantmatch := authorregex.FindStringSubmatch(url) + var wanted string if len(wantmatch) == 2 { wanted = wantmatch[1] } - var buf strings.Builder - fmt.Fprintf(&buf, "%s\n", url) + var htf htfilter.Filter htf.Imager = func(node *html.Node) string { return fmt.Sprintf(" ", htfilter.GetAttr(node, "src")) } + + var buf strings.Builder + fmt.Fprintf(&buf, "%s\n", url) + + divs := tweetsel.MatchAll(root) for i, div := range divs { twp := div.Parent.Parent.Parent link := url @@ -87,7 +89,7 @@ func hootextractor(r io.Reader, url string, seen map[string]bool) string { if author != wanted { continue } - if img := imgsel.MatchFirst(twp); img != nil { + for img := imgsel.MatchFirst(twp); img != nil; imgsel.MatchFirst(twp) { img.Parent.RemoveChild(img) div.AppendChild(img) }