refactor(clickTtTournamentRegistrationService): improve link retrieval and scoring logic
- Updated link retrieval to target specific content areas, enhancing accuracy in finding tournament links. - Added filters to exclude irrelevant links based on href patterns, improving the relevance of selected links. - Enhanced scoring mechanism for link selection by incorporating additional criteria, ensuring better matching of tournament entries.
This commit is contained in:
@@ -245,8 +245,9 @@ class ClickTtTournamentRegistrationService {
|
||||
}
|
||||
|
||||
const titleProfile = getTitleSearchProfile(tournament.title || '');
|
||||
const contentRoot = page.locator('#content-row1, #content, #container').first();
|
||||
|
||||
const tournamentHref = await page.locator('a').evaluateAll((anchors, criteria) => {
|
||||
const tournamentHref = await contentRoot.locator('a').evaluateAll((anchors, criteria) => {
|
||||
const normalize = (value) => String(value || '')
|
||||
.normalize('NFKC')
|
||||
.replace(/\s+/g, ' ')
|
||||
@@ -271,6 +272,7 @@ class ClickTtTournamentRegistrationService {
|
||||
for (const anchor of anchors) {
|
||||
const href = anchor.getAttribute('href');
|
||||
if (!href) continue;
|
||||
if (/dataProtection|legalNotice|logout|contact/i.test(href)) continue;
|
||||
|
||||
const text = normalize(anchor.textContent || '');
|
||||
const contextText = normalize(anchor.closest('tr, li, div, td')?.textContent || '');
|
||||
@@ -279,6 +281,7 @@ class ClickTtTournamentRegistrationService {
|
||||
|
||||
let score = 0;
|
||||
if (wantedTitle && combinedText.includes(wantedTitle)) score += 100;
|
||||
if (text && wantedTitle && text.includes(wantedTitle)) score += 30;
|
||||
|
||||
for (const token of wantedTokens) {
|
||||
if (combinedTokens.has(token)) score += 3;
|
||||
@@ -288,6 +291,9 @@ class ClickTtTournamentRegistrationService {
|
||||
if (combinedTokens.has(token)) score += 8;
|
||||
}
|
||||
|
||||
if (/turnier|meisterschaft|rangliste|pokal/i.test(combinedText)) score += 10;
|
||||
if (/anmelden|meldung|teilnehmer/i.test(combinedText)) score += 5;
|
||||
|
||||
if (score > bestScore) {
|
||||
bestScore = score;
|
||||
bestHref = href;
|
||||
@@ -307,11 +313,11 @@ class ClickTtTournamentRegistrationService {
|
||||
label: tournament.title || 'Turnier',
|
||||
selector: `a[href="${tournamentHref}"]`
|
||||
});
|
||||
await page.locator(`a[href="${tournamentHref}"]`).first().click();
|
||||
await contentRoot.locator(`a[href="${tournamentHref}"]`).first().click();
|
||||
await page.waitForLoadState('domcontentloaded');
|
||||
}
|
||||
|
||||
const href = await page.locator('a').evaluateAll((anchors, criteria) => {
|
||||
const href = await page.locator('#content-row1 a, #content a, #container a').evaluateAll((anchors, criteria) => {
|
||||
const normalize = (value) => String(value || '')
|
||||
.normalize('NFKC')
|
||||
.replace(/\s+/g, ' ')
|
||||
@@ -337,6 +343,7 @@ class ClickTtTournamentRegistrationService {
|
||||
for (const anchor of anchors) {
|
||||
const href = anchor.getAttribute('href');
|
||||
if (!href) continue;
|
||||
if (/dataProtection|legalNotice|logout|contact/i.test(href)) continue;
|
||||
const text = normalize(anchor.textContent || '');
|
||||
if (!text.includes(wantedCompetition)) continue;
|
||||
|
||||
@@ -378,7 +385,7 @@ class ClickTtTournamentRegistrationService {
|
||||
label: competitionName,
|
||||
selector: `a[href="${href}"]`
|
||||
});
|
||||
await page.locator(`a[href="${href}"]`).first().click();
|
||||
await page.locator(`#content-row1 a[href="${href}"], #content a[href="${href}"], #container a[href="${href}"]`).first().click();
|
||||
await page.waitForLoadState('domcontentloaded');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user