From cf74c8e4ea3dd7d5f22cb6b4db50f9482a115a74 Mon Sep 17 00:00:00 2001 From: zsgsdesign Date: Sun, 24 Oct 2021 14:42:24 +0800 Subject: [PATCH] fetching attachments when problem empty --- Crawler.php | 16 +++++++++++++++- babel.json | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Crawler.php b/Crawler.php index 392aefb..d843a7d 100644 --- a/Crawler.php +++ b/Crawler.php @@ -92,6 +92,12 @@ private function _extractCodeForces($pcode, $url) $this->currentProblemCcode = $pcode; $this->imageIndex = 1; + $this->pro["input"] = null; + $this->pro["output"] = null; + $this->pro["note"] = null; + $this->pro["sample"] = null; + $this->pro["description"] = null; + $response = $this->getCodeForcesResponse($url); $contentType = $response->headers['content-type']; $content = $response->body; @@ -167,7 +173,15 @@ private function _extractCodeForces($pcode, $url) } $descriptionSpecificationDOM = $problemDOM->find('div.problem-statement', 0); - $this->pro["description"] = trim($descriptionSpecificationDOM->innertext); + + if(filled(trim(HtmlDomParser::str_get_html($descriptionSpecificationDOM->innertext, true, true, DEFAULT_TARGET_CHARSET, false)->plaintext))) { + $this->pro["description"] = trim($descriptionSpecificationDOM->innertext); + } + + if($this->pro["note"] == $this->pro["description"] && $this->pro["description"] == $this->pro["input"] && $this->pro["input"] == $this->pro["output"] && $this->pro["output"] == null) { + $contestID = $this->pro['contest_id']; + return $this->_extractCodeForces($pcode, "https://codeforces.com/gym/$contestID/attachments"); + } $this->pro["note"] = $this->cacheImage(HtmlDomParser::str_get_html($this->pro["note"], true, true, DEFAULT_TARGET_CHARSET, false)); $this->pro["description"] = $this->cacheImage(HtmlDomParser::str_get_html($this->pro["description"], true, true, DEFAULT_TARGET_CHARSET, false)); diff --git a/babel.json b/babel.json index 96a8e5b..2d2c958 100644 --- a/babel.json +++ b/babel.json @@ -6,7 +6,7 @@ "description": "CodeForces Gym Interface for NOJ", "license": "MIT", "repository": "https://github.com/NJUPTAAA/NOJ_Extension_Babel_Gym", - "version": "0.1.2", + "version": "0.1.3", "website": "https://codeforces.com/gyms", "custom": { "css": "resources/custom.css"