From 95d08eebb86a7461217c7e99325d56e4c11ef662 Mon Sep 17 00:00:00 2001 From: kirillmb Date: Fri, 14 Feb 2020 01:03:15 +0300 Subject: [PATCH 1/3] Add go mod --- go.mod | 8 ++++++++ go.sum | 14 ++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..56ae14e --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module github.com/tolantop/twitter-scraper + +go 1.13 + +require ( + github.com/PuerkitoBio/goquery v1.5.1 + github.com/google/go-cmp v0.4.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..5fc056f --- /dev/null +++ b/go.sum @@ -0,0 +1,14 @@ +github.com/PuerkitoBio/goquery v1.5.1 h1:PSPBGne8NIUWw+/7vFBV+kG2J/5MOjbzc7154OaKCSE= +github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= +github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5zzsLTo= +github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From c5cffefae17e90141c9ec1e9ef7847c6177ba273 Mon Sep 17 00:00:00 2001 From: tolantop <> Date: Wed, 4 Mar 2020 01:53:13 +0300 Subject: [PATCH 2/3] add: detect pin post --- tweets.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tweets.go b/tweets.go index c50705e..4cf5e42 100644 --- a/tweets.go +++ b/tweets.go @@ -24,6 +24,7 @@ type Tweet struct { Hashtags []string HTML string ID string + IsPin bool IsRetweet bool Likes int PermanentURL string @@ -112,6 +113,9 @@ func FetchTweets(user string, last string) ([]*Tweet, error) { s.Find(".js-retweet-text, .QuoteTweet").Each(func(i int, c *goquery.Selection) { tweet.IsRetweet = true }) + s.Find(`span[class="js-pinned-text"]`).Each(func(i int, c *goquery.Selection) { + tweet.IsPin = true + }) s.Find(".ProfileTweet-actionCount").Each(func(i int, c *goquery.Selection) { txt := strings.TrimSpace(c.Text()) if strings.HasSuffix(txt, "likes") { From e64c140c2018d6cf5865fffbcf9fbdf1ff54e01b Mon Sep 17 00:00:00 2001 From: tolantop Date: Wed, 4 Mar 2020 22:10:11 +0300 Subject: [PATCH 3/3] selector change --- tweets.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tweets.go b/tweets.go index 222438b..8ac23b3 100644 --- a/tweets.go +++ b/tweets.go @@ -113,7 +113,7 @@ func FetchTweets(user string, last string) ([]*Tweet, error) { s.Find(".js-retweet-text, .QuoteTweet").Each(func(i int, c *goquery.Selection) { tweet.IsRetweet = true }) - s.Find(`span[class="js-pinned-text"]`).Each(func(i int, c *goquery.Selection) { + s.Find("span.js-pinned-text").Each(func(i int, c *goquery.Selection) { tweet.IsPin = true }) s.Find(".ProfileTweet-actionCount").Each(func(i int, c *goquery.Selection) {