diff --git a/client.go b/client.go index 7582415..dce1914 100644 --- a/client.go +++ b/client.go @@ -36,7 +36,6 @@ func NewClient(baseURL, salt string) *Client { } func (c *Client) CalculateHash(url string) string { - // The hash should be calculated by appending the salt to the URL with a colon separator. data := url + ":" + c.Salt hash := md5.Sum([]byte(data)) return hex.EncodeToString(hash[:]) @@ -71,12 +70,15 @@ func (c *Client) Scrape(ctx context.Context, url, selector string) (ScrapeRespon } defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return ScrapeResponse{}, fmt.Errorf("received non-OK response: %s", resp.Status) + } + body, err := ioutil.ReadAll(resp.Body) if err != nil { return ScrapeResponse{}, fmt.Errorf("failed to read response body: %v", err) } - // Since the response is HTML, we don't need to unmarshal JSON. content := string(body) return ScrapeResponse{