Skip to content

Commit

Permalink
fix(client): should handle js protect after captcha delay
Browse files Browse the repository at this point in the history
  • Loading branch information
NateScarlet committed Aug 16, 2022
1 parent 08c2334 commit c01bd9b
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions pkg/client/get_html.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,23 @@ func GetHTML(ctx context.Context, url string, options ...GetHTMLOption) (res Get
if err != nil {
return
}
defer resp.Body.Close()
res.response = resp
res.body, err = io.ReadAll(resp.Body)
return makeGetHTMLResult(ctx, resp)
}

func makeGetHTMLResult(ctx context.Context, resp *http.Response) (res GetHTMLResult, err error) {
err = func() (err error) {
defer resp.Body.Close()
res.response = resp
res.body, err = io.ReadAll(resp.Body)
if err != nil {
return
}
return
}()
if err != nil {
return
}

err = handleCaptcha(ctx, &res)
if err != nil {
return
Expand Down Expand Up @@ -86,9 +97,7 @@ func handleJSProtect(ctx context.Context, res *GetHTMLResult) (err error) {
if err != nil {
return
}
defer resp.Body.Close()
res.response = resp
res.body, err = io.ReadAll(resp.Body)
*res, err = makeGetHTMLResult(ctx, resp)
return
}

Expand All @@ -105,9 +114,7 @@ func handleCaptcha(ctx context.Context, res *GetHTMLResult) (err error) {
if err != nil {
return
}
defer resp.Body.Close()
res.response = resp
res.body, err = io.ReadAll(resp.Body)
*res, err = makeGetHTMLResult(ctx, resp)
return
}

Expand Down

0 comments on commit c01bd9b

Please sign in to comment.