Fix trends panic
This commit is contained in:
parent
658e55847d
commit
5c9abef879
1 changed files with 6 additions and 0 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
package twitterscraper
|
package twitterscraper
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
// GetTrends return list of trends.
|
// GetTrends return list of trends.
|
||||||
func (s *Scraper) GetTrends() ([]string, error) {
|
func (s *Scraper) GetTrends() ([]string, error) {
|
||||||
req, err := s.newRequest("GET", "https://twitter.com/i/api/2/guide.json")
|
req, err := s.newRequest("GET", "https://twitter.com/i/api/2/guide.json")
|
||||||
|
|
@ -20,6 +22,10 @@ func (s *Scraper) GetTrends() ([]string, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(jsn.Timeline.Instructions[1].AddEntries.Entries) < 2 {
|
||||||
|
return nil, fmt.Errorf("no trend entries found")
|
||||||
|
}
|
||||||
|
|
||||||
var trends []string
|
var trends []string
|
||||||
for _, item := range jsn.Timeline.Instructions[1].AddEntries.Entries[1].Content.TimelineModule.Items {
|
for _, item := range jsn.Timeline.Instructions[1].AddEntries.Entries[1].Content.TimelineModule.Items {
|
||||||
trends = append(trends, item.Item.ClientEventInfo.Details.GuideDetails.TransparentGuideDetails.TrendMetadata.TrendName)
|
trends = append(trends, item.Item.ClientEventInfo.Details.GuideDetails.TransparentGuideDetails.TrendMetadata.TrendName)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue