mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Add support for setting cookies in the scraper (#934)
This commit is contained in:
@@ -17,9 +17,10 @@ import (
|
||||
"github.com/chromedp/cdproto/network"
|
||||
"github.com/chromedp/chromedp"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"golang.org/x/net/html/charset"
|
||||
"golang.org/x/net/publicsuffix"
|
||||
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
)
|
||||
|
||||
// Timeout for the scrape http request. Includes transfer time. May want to make this
|
||||
@@ -42,6 +43,9 @@ func loadURL(url string, scraperConfig config, globalConfig GlobalConfig) (io.Re
|
||||
return nil, er
|
||||
}
|
||||
|
||||
setCookies(jar, scraperConfig)
|
||||
printCookies(jar, scraperConfig, "Jar cookies set from scraper")
|
||||
|
||||
client := &http.Client{
|
||||
Timeout: scrapeGetTimeout,
|
||||
// defaultCheckRedirect code with max changed from 10 to 20
|
||||
@@ -76,6 +80,7 @@ func loadURL(url string, scraperConfig config, globalConfig GlobalConfig) (io.Re
|
||||
}
|
||||
|
||||
bodyReader := bytes.NewReader(body)
|
||||
printCookies(jar, scraperConfig, "Jar cookies found for scraper urls")
|
||||
|
||||
return charset.NewReader(bodyReader, resp.Header.Get("Content-Type"))
|
||||
}
|
||||
@@ -140,6 +145,8 @@ func urlFromCDP(url string, driverOptions scraperDriverOptions, globalConfig Glo
|
||||
var res string
|
||||
err := chromedp.Run(ctx,
|
||||
network.Enable(),
|
||||
setCDPCookies(driverOptions),
|
||||
printCDPCookies(driverOptions, "Cookies found"),
|
||||
chromedp.Navigate(url),
|
||||
chromedp.Sleep(sleepDuration),
|
||||
chromedp.ActionFunc(func(ctx context.Context) error {
|
||||
@@ -150,6 +157,7 @@ func urlFromCDP(url string, driverOptions scraperDriverOptions, globalConfig Glo
|
||||
res, err = dom.GetOuterHTML().WithNodeID(node.NodeID).Do(ctx)
|
||||
return err
|
||||
}),
|
||||
printCDPCookies(driverOptions, "Cookies set"),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user