mtg-decks-downloader

Tool to download Magic: The Gathering decklists from the Internet
git clone https://kevincorvisier.fr/git/mtg-decks-downloader.git
Log | Files | Refs | README

commit 7fe04140ca47fd3dd24c41fa8479044e19ea88d9
parent bfb691183c1a97b6a4d82af84df0cc05508b0602
Author: Kevin Corvisier <git@kevincorvisier.fr>
Date:   Thu, 30 Jan 2025 18:25:29 +0900

Fix decks downloader crashing at the end of a tcdecks archetype download
Diffstat:
Msrc/main/java/fr/kevincorvisier/mtg/dd/downloaders/TcdecksDecklistDownloader.java | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/main/java/fr/kevincorvisier/mtg/dd/downloaders/TcdecksDecklistDownloader.java b/src/main/java/fr/kevincorvisier/mtg/dd/downloaders/TcdecksDecklistDownloader.java @@ -133,8 +133,6 @@ public class TcdecksDecklistDownloader implements DecklistDownloader { crawler.navigateTo(next); - next = new URL(crawler.findElement(By.xpath("//a[text()='Next']")).getAttribute("href")); - for (final WebElement tr : crawler.findElements(By.xpath("//table[@class='tourney_list']/tbody/tr"))) { if (hasElement(tr, By.xpath("th"))) @@ -160,7 +158,16 @@ public class TcdecksDecklistDownloader implements DecklistDownloader consumers.process(metadataFactory.create(downloadUrl, player.getText(), archetype, LocalDate.parse(date.getText(), DateTimeFormatter.ofPattern("dd/MM/yyyy")))); } - } while (stopCondition.capacity() > 0); + + try + { + next = new URL(crawler.findElement(By.xpath("//a[text()='Next']")).getAttribute("href")); + } + catch (final NoSuchElementException e) + { + next = null; + } + } while (stopCondition.capacity() > 0 && next != null); } private void downloadTournament(final URL url) throws MalformedURLException