From ef7eb9dbb1b3704006f665eac14f9ae04049636a Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Fri, 10 Jul 2026 20:27:58 +0800 Subject: [PATCH] =?UTF-8?q?branch=5Fnumber=E6=A3=80=E6=B5=8B=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/surugaya_client.py | 24 +++++++++++++++--------- tests/test_other_shop_parser.py | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/app/services/surugaya_client.py b/app/services/surugaya_client.py index b270f7f..8c5e79c 100644 --- a/app/services/surugaya_client.py +++ b/app/services/surugaya_client.py @@ -376,16 +376,22 @@ class SurugayaClient: shipping_note_node = row.css_first("ul.shipping_campaing_info li.padT5") shipping_note = shipping_note_node.text().strip() if shipping_note_node else "" + # branch_number 优先从 detail_url 的查询参数中提取(与 detail_url 保持一致), + # data-zaiko_data 仅作为兜底(极少数情况下 href 未携带 branch_number 时)。 branch_number = "" - campaign_node = row.css_first("li.ajax-campaign-placeholder") - if campaign_node: - zaiko_raw = campaign_node.attributes.get("data-zaiko_data") or "" - if zaiko_raw: - try: - zaiko = json.loads(zaiko_raw) - branch_number = str(zaiko.get("branch_number", "")) - except json.JSONDecodeError: - pass + if detail_href: + branch_number = (parse_qs(urlparse(detail_href).query).get("branch_number") or [""])[0] + + if not branch_number: + campaign_node = row.css_first("li.ajax-campaign-placeholder") + if campaign_node: + zaiko_raw = campaign_node.attributes.get("data-zaiko_data") or "" + if zaiko_raw: + try: + zaiko = json.loads(zaiko_raw) + branch_number = str(zaiko.get("branch_number", "")) + except json.JSONDecodeError: + pass items.append( OtherShopItem( diff --git a/tests/test_other_shop_parser.py b/tests/test_other_shop_parser.py index 04ac283..612ff4a 100644 --- a/tests/test_other_shop_parser.py +++ b/tests/test_other_shop_parser.py @@ -74,17 +74,35 @@ OTHER_SHOP_HTML = """ +
980円