branch_number检测逻辑

This commit is contained in:
2026-07-10 20:27:58 +08:00
parent 118667d01f
commit ef7eb9dbb1
2 changed files with 46 additions and 11 deletions
+31 -2
View File
@@ -74,17 +74,35 @@ OTHER_SHOP_HTML = """
</ul>
</td>
</tr>
<tr class="item">
<td><p><strong class="text-red text-bold mgnL10">980円</strong></p></td>
<td>
<a href="/product/detail/602274031?tenpo_cd=400567&branch_number=0003">
<h2 class="title_product">中古</h2>
</a>
</td>
<td>
<div class="space_text_1 mgnB5"><strong><a href="/shop/400567">駿河屋 テスト店</a></strong></div>
<div class="star_group mgnB5"></div>
<div>4.5(10件)</div>
</td>
<td>
<ul class="shipping_campaing_info">
<li class="padT5">1日〜3日以内に発送します</li>
</ul>
</td>
</tr>
</table>
</div>
"""
def test_parse_other_shop_list_extracts_all_rows() -> None:
"""行分别为:加盟店、官方自营、市场店铺,均应被正确解析。"""
"""行分别为:加盟店、官方自营、市场店铺、无 data-zaiko_data 的加盟店,均应被正确解析。"""
tree = HTMLParser(OTHER_SHOP_HTML)
items = SurugayaClient._parse_other_shop_list(tree)
assert len(items) == 3
assert len(items) == 4
def test_parse_other_shop_list_franchise_row() -> None:
@@ -133,6 +151,17 @@ def test_parse_other_shop_list_marketplace_row() -> None:
assert item.rating_count == 46
def test_parse_other_shop_list_branch_number_falls_back_to_detail_url() -> None:
"""无 ajax-campaign-placeholder(无 data-zaiko_data)时,branch_number 应从 detail_url 查询参数回退提取。"""
tree = HTMLParser(OTHER_SHOP_HTML)
item = SurugayaClient._parse_other_shop_list(tree)[3]
assert item.branch_number == "0003"
assert item.detail_url == (
"https://www.suruga-ya.jp/product/detail/602274031?tenpo_cd=400567&branch_number=0003"
)
def test_parse_other_shop_list_empty_html_returns_empty_list() -> None:
"""页面结构不包含 tbl_all 时(如解析失败/改版),应返回空列表而非抛异常。"""
tree = HTMLParser("<html><body>no table here</body></html>")