-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This fetcher utilizes an http client that is capable to simulate the fingerprints of common browsers. It is helpful to bypass websites that block by checking the TLS fingerprint of an HTTP client
- Loading branch information
Showing
5 changed files
with
153 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package stealth | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"net/http" | ||
"sync" | ||
|
||
"github.com/gosom/scrapemate" | ||
|
||
"github.com/Noooste/azuretls-client" | ||
) | ||
|
||
type stealthFetch struct { | ||
} | ||
|
||
func New() scrapemate.HTTPFetcher { | ||
return &stealthFetch{} | ||
} | ||
|
||
func (o *stealthFetch) Close() error { | ||
return nil | ||
} | ||
|
||
func (o *stealthFetch) Fetch(ctx context.Context, job scrapemate.IJob) scrapemate.Response { | ||
u := job.GetFullURL() | ||
reqBody := getBuffer() | ||
|
||
defer putBuffer(reqBody) | ||
|
||
if len(job.GetBody()) > 0 { | ||
reqBody.Write(job.GetBody()) | ||
} | ||
|
||
session := azuretls.NewSessionWithContext(ctx) | ||
|
||
defer session.Close() | ||
|
||
session.Browser = azuretls.Firefox | ||
|
||
req := azuretls.Request{ | ||
Method: job.GetMethod(), | ||
Url: u, | ||
} | ||
req.SetContext(ctx) | ||
|
||
var ans scrapemate.Response | ||
|
||
resp, err := session.Do(&req) | ||
if err != nil { | ||
ans.Error = err | ||
|
||
return ans | ||
} | ||
|
||
ans.StatusCode = resp.StatusCode | ||
ans.Headers = http.Header{} | ||
|
||
for k, v := range resp.Header { | ||
ans.Headers[k] = v | ||
} | ||
|
||
ans.Body = resp.Body | ||
ans.URL = u | ||
|
||
return ans | ||
} | ||
|
||
var bufferPool = sync.Pool{ | ||
New: func() interface{} { | ||
return new(bytes.Buffer) | ||
}, | ||
} | ||
|
||
func getBuffer() *bytes.Buffer { | ||
//nolint:errcheck // we don't care about errors here | ||
b := bufferPool.Get().(*bytes.Buffer) | ||
b.Reset() | ||
|
||
return b | ||
} | ||
|
||
func putBuffer(buf *bytes.Buffer) { | ||
bufferPool.Put(buf) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters