feat: add feikuai category and search parsing

This commit is contained in:
Harold
2026-04-26 08:50:15 +08:00
parent f5e50d7dc1
commit b0b2065e44
2 changed files with 143 additions and 0 deletions
+48
View File
@@ -1,6 +1,7 @@
import unittest
from importlib.machinery import SourceFileLoader
from pathlib import Path
from unittest.mock import patch
ROOT = Path(__file__).resolve().parents[1]
@@ -28,3 +29,50 @@ class TestFeikuaiSpider(unittest.TestCase):
def test_home_video_content_returns_empty_list(self):
self.assertEqual(self.spider.homeVideoContent(), {"list": []})
@patch.object(Spider, "_request_html")
def test_category_content_parses_short_vod_id(self, mock_request_html):
mock_request_html.return_value = """
<a class="module-poster-item" href="/voddetail/12345.html" title="分类影片">
<img class="lazy" data-original="/cover.jpg" />
<div class="module-item-note">更新至10集</div>
</a>
"""
result = self.spider.categoryContent("2", "3", False, {})
self.assertEqual(
mock_request_html.call_args.args[0],
"https://feikuai.tv/vodshow/2--------3---.html",
)
self.assertEqual(
result["list"],
[
{
"vod_id": "/voddetail/12345.html",
"vod_name": "分类影片",
"vod_pic": "https://feikuai.tv/cover.jpg",
"vod_remarks": "更新至10集",
}
],
)
self.assertNotIn("pagecount", result)
@patch.object(Spider, "_request_html")
def test_search_content_parses_cards_and_blank_keyword(self, mock_request_html):
blank = self.spider.searchContent("", False, "1")
self.assertEqual(blank, {"page": 1, "limit": 0, "total": 0, "list": []})
mock_request_html.assert_not_called()
mock_request_html.return_value = """
<div class="module-card-item module-item">
<a class="module-card-item-poster" href="/voddetail/67890.html"></a>
<div class="module-item-pic"><img data-original="/search.jpg" /></div>
<div class="module-card-item-title"><strong>搜索命中</strong></div>
<div class="module-item-note">HD</div>
</div>
"""
result = self.spider.searchContent("繁花", False, "2")
self.assertEqual(
mock_request_html.call_args.args[0],
"https://feikuai.tv/label/search_ajax.html?wd=%E7%B9%81%E8%8A%B1&by=time&order=desc&page=2",
)
self.assertEqual(result["list"][0]["vod_id"], "/voddetail/67890.html")