From 8d04e4d8e0ce7a3fc23d6f81fe13dc661df64d24 Mon Sep 17 00:00:00 2001 From: Harold <8866033@gmail.com> Date: Mon, 20 Apr 2026 16:37:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B0=81=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/tests/test_至臻.py | 29 +++++++++++++++++++++++++++++ py/至臻.py | 27 +++++++++++++++++++-------- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/py/tests/test_至臻.py b/py/tests/test_至臻.py index 94cf604..73d403f 100644 --- a/py/tests/test_至臻.py +++ b/py/tests/test_至臻.py @@ -111,6 +111,35 @@ class TestZhiZhenSpider(unittest.TestCase): ], ) + def test_parse_cards_normalizes_nested_absolute_cover_url(self): + html = """ +
+ """ + self.assertEqual( + self.spider._parse_cards(html), + [ + { + "vod_id": "/index.php/vod/detail/id/123.html", + "vod_name": "嵌套封面", + "vod_pic": "https://img.ffzy888.com/upload/vod/2024-06-13/17182715511.jpg", + "vod_remarks": "HD", + "vod_year": "2024", + } + ], + ) + @patch.object(Spider, "_request_html") def test_category_content_builds_reference_url_and_returns_page_payload(self, mock_request_html): mock_request_html.return_value = """ diff --git a/py/至臻.py b/py/至臻.py index b0156d1..627d065 100644 --- a/py/至臻.py +++ b/py/至臻.py @@ -70,6 +70,15 @@ class Spider(BaseSpider): def _clean_text(self, text): return re.sub(r"\s+", " ", str(text or "").replace("\xa0", " ")).strip() + def _normalize_img_url(self, img_url): + raw = str(img_url or "").strip() + if not raw: + return "" + matches = list(re.finditer(r"https?://", raw, re.I)) + if len(matches) > 1: + raw = raw[matches[-1].start() :] + return raw + def _detect_pan_type(self, url): raw = str(url or "").strip() for pan_type, title, pattern in self.pan_patterns: @@ -113,7 +122,7 @@ class Spider(BaseSpider): { "vod_id": href, "vod_name": title, - "vod_pic": self._build_url(pic), + "vod_pic": self._build_url(self._normalize_img_url(pic)), "vod_remarks": remarks, "vod_year": year, } @@ -153,7 +162,7 @@ class Spider(BaseSpider): { "vod_id": href, "vod_name": title, - "vod_pic": self._build_url(pic), + "vod_pic": self._build_url(self._normalize_img_url(pic)), "vod_remarks": remarks, } ) @@ -177,12 +186,14 @@ class Spider(BaseSpider): "vod_id": vod_id, "vod_name": self._clean_text("".join(root.xpath("//*[contains(@class,'page-title')][1]//text()"))), "vod_pic": self._build_url( - "".join( - root.xpath( - "//*[contains(@class,'mobile-play')]//*[contains(@class,'lazyload')][1]/@data-src | " - "//*[contains(@class,'mobile-play')]//*[contains(@class,'lazyload')][1]/@src" - ) - ).strip() + self._normalize_img_url( + "".join( + root.xpath( + "//*[contains(@class,'mobile-play')]//*[contains(@class,'lazyload')][1]/@data-src | " + "//*[contains(@class,'mobile-play')]//*[contains(@class,'lazyload')][1]/@src" + ) + ).strip() + ) ), "vod_year": "", "vod_director": "",