Skip to content

Commit

Permalink
mmm
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikidepia committed Jul 23, 2024
1 parent 377bf0f commit 90e478d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions handlers/scraper/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ func (i *InstaData) ScrapeData() error {
if err == nil && len(body) > 0 {
break
}
} else if err != nil {
slog.Error("Failed to scrape data from embedHTML", "postID", i.PostID, "err", err)
}
}

Expand Down Expand Up @@ -442,10 +444,17 @@ func scrapeFromGQL(postID string) ([]byte, error) {
}

client := http.Client{Transport: transport, Timeout: timeout}
res, err := client.Do(req)
if err != nil || res == nil {
return nil, err
for retries := 0; retries < 3; retries++ {
res, err := client.Do(req)
if res != nil && res.StatusCode == 200 {
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err == nil && len(body) > 0 {
return body, nil
}
} else if err != nil {
slog.Error("Failed to scrape data from GraphQL API", "postID", postID, "err", err)
}
}
defer res.Body.Close()
return io.ReadAll(res.Body)
return nil, ErrNotFound
}

0 comments on commit 90e478d

Please sign in to comment.