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 624db49c8be3f4a38d9aeeff0f006790672911c6
parent ad3cadbc1b3d5a21faed0275912b04fd413ed989
Author: Kevin Corvisier <git@kevincorvisier.fr>
Date:   Fri,  6 Jun 2025 05:21:18 +0900

Update TC Decks search downloads
Diffstat:
Msrc/main/java/fr/kevincorvisier/mtg/dd/downloaders/TcdecksDecklistDownloader.java | 25++++++++++++++++---------
1 file changed, 16 insertions(+), 9 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 @@ -213,11 +213,13 @@ public class TcdecksDecklistDownloader implements DecklistDownloader } } - private void downloadSearch(final URL url) + private void downloadSearch(final URL url) throws MalformedURLException { - try + URL next = url; + + do { - crawler.navigateTo(url); + crawler.navigateTo(next); for (final WebElement tr : crawler.findElements(By.xpath("//table[@class='search_list']/tbody/tr"))) { @@ -226,17 +228,22 @@ public class TcdecksDecklistDownloader implements DecklistDownloader final WebElement archetype = tr.findElement(By.xpath("td[@data-th='Archetype']/a")); final WebElement player = tr.findElement(By.xpath("td[@data-th='Player']/a")); - final WebElement date = tr.findElement(By.xpath("td[@data-th='Date']/a")); + final WebElement date = tr.findElement(By.xpath("td[@data-th='Date']")); final URL downloadUrl = toDownloadUrl(archetype.getAttribute("href")); consumers.process(metadataFactory.create(downloadUrl, player.getText(), archetype.getText(), LocalDate.parse(date.getText(), DateTimeFormatter.ofPattern("dd/MM/yyyy")))); + + try + { + next = new URL(crawler.findElement(By.xpath("//a[text()='Next']")).getAttribute("href")); + } + catch (final NoSuchElementException e) + { + next = null; + } } - } - catch (final Exception e) - { - log.error("downloadSearch: url={}", url, e); - } + } while (stopCondition.capacity() > 0 && next != null); } private boolean hasElement(final WebElement element, final By by)