I'm making a bot that will store posts on Reddit that have more than 1000 upvotes. I intend to store the links and the urls.
I'm having trouble in finding a way to match the links/urls of the posts that have more than 1000 upvotes, I'm using the following GoQuery functions:
Getting the upvotes:
doc.Find(".score.unvoted").Each(func(i int, s *goquery.Selection) {
voteValue, _ := strconv.Atoi(s.Text())
greaterThan(voteValue)
if strings.Contains(s.Text(), "k") || greaterThan(voteValue) {
postUpvotes = append(postUpvotes, s.Text())
}
fmt.Println("UPVOTES SLICE", postUpvotes)
})
Getting the URL's:
doc.Find(".title.may-blank").Each(func(i int, s *goquery.Selection) {
url, ok := s.Attr("href")
if ok {
link = url
links = append(links, link)
fmt.Println("LINKS SLICE -> ", links)
}
})
Getting the post title:
doc.Find(".title.title.may-blank").Each(func(i int, s *goquery.Selection) {
fmt.Println("Titulo", s.Text())
title = s.Text()
titles = append(titles, title)
})
The trouble is that, despite I can get the right amount of upvotes, some links and urls from posts are from posts that have less than 1000 upvotes, and I don't want that.
I've tried to replicate the way that I got the upvotes, but it doesn't works either.
Hope someone can help me or give me an insight, thanks in advance!
If the post is too long, let me know and I'll create a gist.