Fix scraping multiple ads (#126)

Upstream has changed their content generation system. When using the same http client, the first page looks as we expect it, but subsequent pages look totally different. I can't find out why that is, but it's not an issue of this tool.

So, the "fix" is to abandon client reuse and re-initialize a new client for every http request. However, the image fetcher keeps resusing the client.

Co-authored-by: Thomas von Dein <tom@vondein.org>
Reviewed-on: https://codeberg.org/scip/kleingebaeck/pulls/126
This commit is contained in:
T. von Dein
2026-10-12 21:29:49 +02:00
parent 0d5ee0b485
commit d9f2f0a712
15 changed files with 251 additions and 69 deletions

View File

@@ -405,6 +405,7 @@ func InitValidSources() []Adsource {
empty := AdConfig{}
// prepare urls for the listing pages
// nolint:prealloc
ads := []Adsource{
{
uri: fmt.Sprintf("%s%s?userId=1", Baseuri, Listuri),
@@ -436,7 +437,7 @@ func InitInvalidSources() []Adsource {
ads := []Adsource{
{
// valid ad page but without content
uri: fmt.Sprintf("%s/s-anzeige/empty/1", Baseuri),
uri: Baseuri + "/s-anzeige/empty/1",
content: GetTemplate(nil, &empty, EMPTYPAGE),
},
{
@@ -446,18 +447,18 @@ func InitInvalidSources() []Adsource {
},
{
// some invalid page path
uri: fmt.Sprintf("%s/anzeige/name/1", Baseuri),
uri: Baseuri + "/anzeige/name/1",
content: GetTemplate(nil, &empty, "<html></html>"),
},
{
// some none-ad page
uri: fmt.Sprintf("%s/anzeige/name/1/foo/bar", Baseuri),
uri: Baseuri + "/anzeige/name/1/foo/bar",
content: GetTemplate(nil, &empty, "<html>HTTP 404: /eine-anzeige/ does not exist!</html>"),
status: 404,
},
{
// valid ad page but 503
uri: fmt.Sprintf("%s/s-anzeige/503/1", Baseuri),
uri: Baseuri + "/s-anzeige/503/1",
content: GetTemplate(nil, &empty, "<html>HTTP 503: service unavailable</html>"),
status: 503,
},
@@ -531,6 +532,7 @@ func TestMain(t *testing.T) {
defer func() { os.Args = oldargs }()
httpmock.Activate()
defer httpmock.DeactivateAndReset()
// prepare httpmock responders
@@ -568,6 +570,7 @@ func TestMainInvalids(t *testing.T) {
defer func() { os.Args = oldargs }()
httpmock.Activate()
defer httpmock.DeactivateAndReset()
// prepare httpmock responders