From 354cea09a7e8fa4bc83c9e118083891a678bad1b Mon Sep 17 00:00:00 2001 From: Jonathan Kay Date: Sun, 8 Jun 2025 15:57:41 -0400 Subject: [PATCH] [GoComicsBridge] Add fallback when link to current comic is missing (#4589) --- bridges/GoComicsBridge.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bridges/GoComicsBridge.php b/bridges/GoComicsBridge.php index a5784091..8e78ce5e 100644 --- a/bridges/GoComicsBridge.php +++ b/bridges/GoComicsBridge.php @@ -32,8 +32,20 @@ class GoComicsBridge extends BridgeAbstract { $link = $this->getURI(); $landingpage = getSimpleHTMLDOM($link); - - $link = $landingpage->find('div[data-post-url]', 0)->getAttribute('data-post-url'); + $element = $landingpage->find('div[data-post-url]', 0); + if ($element) { + $link = $element->getAttribute('data-post-url'); + } else { // fallback for comics without data-post-url (assumes daily comic) + $nextcomiclink = $landingpage->find('a[class*="ComicNavigation_controls__button_previous__"]', 0)->href; + preg_match('/(\d{4}\/\d{2}\/\d{2})/', $nextcomiclink, $nclmatches); + if (!empty($nclmatches[1])) { + $nextdate = new DateTime($nclmatches[1]); + $nextdate = $nextdate->modify('+1 day')->format('Y/m/d'); + $link = $link . '/' . $nextdate; + } else { + throw new \Exception('Could not find the first comic URL. Please create a new GitHub issue.'); + } + } for ($i = 0; $i < $this->getInput('limit'); $i++) { $html = getSimpleHTMLDOM($link);