0

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.

danibrum
  • 459
  • 8
  • 21
  • How does your `greaterThan()` function look like? – Z. Kosanovic Oct 04 '20 at 20:59
  • 1
    Not a solution for your question, but Reddit offers most of its data publicly as JSON, which may be easier to process: https://www.reddit.com/r/javascript/comments/8yg6ig/adding_json_onto_the_end_of_most_reddit_urls/ – fstanis Oct 04 '20 at 23:00
  • @Z.Kosanovic it receives an integer as a parameter, if the integer is >= 1000, it returns true, if it isn't, returns false. – danibrum Oct 04 '20 at 23:22
  • @fstanis I didn't know that, I'm going to try using JSON, it'll probably be easier to manipulate the data. Thanks. – danibrum Oct 04 '20 at 23:23

0 Answers0