twitter-scraper
twitter-scraper copied to clipboard
The tweets gained by query standard operators is much less than expected
I attempted to search for tweets using standard operators with "river pollution" as my keyword. My goal was to find tweets related to this topic and discover the location of the authors. My code is shown as:
package main
import ( "context" "fmt" twitterscraper "github.com/n0madic/twitter-scraper" "github.com/xuri/excelize/v2" "strconv" "time" )
func main() { scraper := twitterscraper.New() err := scraper.Login("XXX", "XXX") if err != nil { panic(err) }
f:=excelize.NewFile()
sum := 2
f.SetCellValue("Sheet1","A1","UserName")
f.SetCellValue("Sheet1","B1","UserID")
f.SetCellValue("Sheet1","C1","Text")
f.SetCellValue("Sheet1","D1","Views")
f.SetCellValue("Sheet1","E1","Likes")
f.SetCellValue("Sheet1","F1","Retweets")
f.SetCellValue("Sheet1","G1","Place")
f.SetCellValue("Sheet1","H1","Time")
f.SetCellValue("Sheet1","I1","TimeStamp")
f.SetCellValue("Sheet1","J1","Hashtags")
f.SetCellValue("Sheet1","K1","Replies")
f.SetCellValue("Sheet1","L1","ID")
f.SetCellValue("Sheet1","M1","Mentions")
f.SetCellValue("Sheet1","N1","Names")
f.SetCellValue("Sheet1","O1","HTML")
for tweet := range scraper.SearchTweets(context.Background(),
"river pollution -filter:en", 1000) {
if tweet.Error != nil {
panic(tweet.Error)
}
//fmt.Println(tweet.Text)
fmt.Println(sum)
sumindex := strconv.Itoa(sum)
sum_A:="A"
sum_A += sumindex
sum_B:="B"
sum_B += sumindex
sum_C:="C"
sum_C += sumindex
sum_D:="D"
sum_D += sumindex
sum_E:="E"
sum_E += sumindex
sum_F:="F"
sum_F += sumindex
sum_G:="G"
sum_G += sumindex
sum_H:="H"
sum_H += sumindex
sum_I:="I"
sum_I += sumindex
sum_J:="J"
sum_J += sumindex
sum_K:="K"
sum_K += sumindex
sum_L:="L"
sum_L += sumindex
sum_M:="M"
sum_M += sumindex
sum_N:="N"
sum_N += sumindex
sum_O:="O"
sum_O += sumindex
t:=tweet.Timestamp
views:=strconv.Itoa(tweet.Views)
likes:=strconv.Itoa(tweet.Likes)
retweets:=strconv.Itoa(tweet.Retweets)
//timei:=time.Unix(t,0).Format("2023-08-01 03:15:36 +0000 +0000")
timei:=tweet.TimeParsed.Format("2006-01-02 15:04:05")
//place:=strconv.Itoa(tweet.Place)
//fmt.Println(sum_A)
//fmt.Println(sum_B)
//fmt.Println(sum_C)
//fmt.Println(tweet.TimeParsed.Format("2006-01-02 15:04:05"))
//fmt.Println(tweet.Hashtags)
f.SetCellValue("Sheet1",sum_A,tweet.Username)
f.SetCellValue("Sheet1",sum_B,tweet.UserID)
f.SetCellValue("Sheet1",sum_C,tweet.Text)
f.SetCellValue("Sheet1",sum_D,views)
f.SetCellValue("Sheet1",sum_E,likes)
f.SetCellValue("Sheet1",sum_F,retweets)
f.SetCellValue("Sheet1",sum_G,tweet.Place)
f.SetCellValue("Sheet1",sum_H,timei)
f.SetCellValue("Sheet1",sum_I,t)
f.SetCellValue("Sheet1",sum_J,tweet.Hashtags)
f.SetCellValue("Sheet1",sum_K,tweet.Replies)
f.SetCellValue("Sheet1",sum_L,tweet.ID)
f.SetCellValue("Sheet1",sum_M,tweet.Mentions)
f.SetCellValue("Sheet1",sum_N,tweet.Name)
f.SetCellValue("Sheet1",sum_O,tweet.HTML)
sum+=1
time.Sleep(1*time.Second)
}
err2:=f.SaveAs("Test4.xlsx")
if err2 != nil{
fmt.Println(err)
}
}
The problem is that the total tweets I gained is only 240, which is much less than the expectation. I think there should be something wrong with my code. If possible, would you mind you guys taking a sight to see what I can do about it? Thanks in advance!