File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 2121CRAWLER_TYPE = (
2222 "search" # 爬取类型,search(关键词搜索) | detail(帖子详情)| creator(创作者主页数据)
2323)
24+ # 微博搜索类型 default (综合) | real_time (实时) | popular (热门) | video (视频)
25+ WEIBO_SEARCH_TYPE = "popular"
2426# 自定义User Agent(暂时仅对XHS有效)
2527UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0"
2628
Original file line number Diff line number Diff line change @@ -124,6 +124,20 @@ async def search(self):
124124 if config .CRAWLER_MAX_NOTES_COUNT < weibo_limit_count :
125125 config .CRAWLER_MAX_NOTES_COUNT = weibo_limit_count
126126 start_page = config .START_PAGE
127+
128+ # Set the search type based on the configuration for weibo
129+ if config .WEIBO_SEARCH_TYPE == "default" :
130+ search_type = SearchType .DEFAULT
131+ elif config .WEIBO_SEARCH_TYPE == "real_time" :
132+ search_type = SearchType .REAL_TIME
133+ elif config .WEIBO_SEARCH_TYPE == "popular" :
134+ search_type = SearchType .POPULAR
135+ elif config .WEIBO_SEARCH_TYPE == "video" :
136+ search_type = SearchType .VIDEO
137+ else :
138+ utils .logger .error (f"[WeiboCrawler.search] Invalid WEIBO_SEARCH_TYPE: { config .WEIBO_SEARCH_TYPE } " )
139+ return
140+
127141 for keyword in config .KEYWORDS .split ("," ):
128142 source_keyword_var .set (keyword )
129143 utils .logger .info (f"[WeiboCrawler.search] Current search keyword: { keyword } " )
@@ -137,7 +151,7 @@ async def search(self):
137151 search_res = await self .wb_client .get_note_by_keyword (
138152 keyword = keyword ,
139153 page = page ,
140- search_type = SearchType . DEFAULT
154+ search_type = search_type
141155 )
142156 note_id_list : List [str ] = []
143157 note_list = filter_search_result_card (search_res .get ("cards" ))
You can’t perform that action at this time.
0 commit comments