chatgpt-mirai-qq-bot-web-search 0.2.12__py3-none-any.whl → 0.2.14__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {chatgpt_mirai_qq_bot_web_search-0.2.12.dist-info → chatgpt_mirai_qq_bot_web_search-0.2.14.dist-info}/METADATA +1 -1
- {chatgpt_mirai_qq_bot_web_search-0.2.12.dist-info → chatgpt_mirai_qq_bot_web_search-0.2.14.dist-info}/RECORD +7 -7
- web_search/web_searcher.py +8 -21
- {chatgpt_mirai_qq_bot_web_search-0.2.12.dist-info → chatgpt_mirai_qq_bot_web_search-0.2.14.dist-info}/LICENSE +0 -0
- {chatgpt_mirai_qq_bot_web_search-0.2.12.dist-info → chatgpt_mirai_qq_bot_web_search-0.2.14.dist-info}/WHEEL +0 -0
- {chatgpt_mirai_qq_bot_web_search-0.2.12.dist-info → chatgpt_mirai_qq_bot_web_search-0.2.14.dist-info}/entry_points.txt +0 -0
- {chatgpt_mirai_qq_bot_web_search-0.2.12.dist-info → chatgpt_mirai_qq_bot_web_search-0.2.14.dist-info}/top_level.txt +0 -0
@@ -1,11 +1,11 @@
|
|
1
1
|
web_search/__init__.py,sha256=_vfIxeLqXc53QoZ8sHzw_SbGkxb2CTRQdd1phQmC8GM,6147
|
2
2
|
web_search/blocks.py,sha256=QuXt3KMuY4hUW-ucleNYXFvW6YbUAB4Xu4m_SxdCd-U,9152
|
3
3
|
web_search/config.py,sha256=DhLiERBJR2V5Boglf7Aq9Rbc4vsvLIh67CrLDIPeqA0,398
|
4
|
-
web_search/web_searcher.py,sha256=
|
4
|
+
web_search/web_searcher.py,sha256=gYfD0K4_zTIn0pDbB2BABpw7poFuAC4mohJmQWL-3I4,21285
|
5
5
|
web_search/example/roleplayWithWebSearch.yaml,sha256=C-dGy3z8gcRcmxzurssP-kPRLqMf1TYR-nnNUaJjISE,7468
|
6
|
-
chatgpt_mirai_qq_bot_web_search-0.2.
|
7
|
-
chatgpt_mirai_qq_bot_web_search-0.2.
|
8
|
-
chatgpt_mirai_qq_bot_web_search-0.2.
|
9
|
-
chatgpt_mirai_qq_bot_web_search-0.2.
|
10
|
-
chatgpt_mirai_qq_bot_web_search-0.2.
|
11
|
-
chatgpt_mirai_qq_bot_web_search-0.2.
|
6
|
+
chatgpt_mirai_qq_bot_web_search-0.2.14.dist-info/LICENSE,sha256=ILBn-G3jdarm2w8oOrLmXeJNU3czuJvVhDLBASWdhM8,34522
|
7
|
+
chatgpt_mirai_qq_bot_web_search-0.2.14.dist-info/METADATA,sha256=Li4wXJNuG8jkqSQM3-EuR_X4Fx7qmopEViUjwxlzpDE,1735
|
8
|
+
chatgpt_mirai_qq_bot_web_search-0.2.14.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
9
|
+
chatgpt_mirai_qq_bot_web_search-0.2.14.dist-info/entry_points.txt,sha256=o3kRDSdSmSdnCKlK6qS57aN0WpI4ab-Nxub2NwUrjf0,64
|
10
|
+
chatgpt_mirai_qq_bot_web_search-0.2.14.dist-info/top_level.txt,sha256=PoNm8MJYw_y8RTMaNlY0ePLoNHxVUAE2IHDuL5fFubI,11
|
11
|
+
chatgpt_mirai_qq_bot_web_search-0.2.14.dist-info/RECORD,,
|
web_search/web_searcher.py
CHANGED
@@ -31,8 +31,8 @@ class WebSearcher:
|
|
31
31
|
self.video_ids = self._load_video_ids()
|
32
32
|
self.search_engines = {
|
33
33
|
'bing': {
|
34
|
-
'url': 'https://
|
35
|
-
'selectors': ['.b_algo'
|
34
|
+
'url': 'https://www.bing.com/search?q={}',
|
35
|
+
'selectors': ['.b_algo'],
|
36
36
|
'title_selector': 'h2',
|
37
37
|
'link_selector': 'h2 a',
|
38
38
|
'snippet_selector': '.b_caption p'
|
@@ -62,10 +62,8 @@ class WebSearcher:
|
|
62
62
|
async def _ensure_initialized(self,proxy):
|
63
63
|
"""确保浏览器已初始化"""
|
64
64
|
try:
|
65
|
-
if self.context:
|
66
|
-
return self.context
|
67
|
-
self.playwright = await async_playwright().start()
|
68
65
|
|
66
|
+
self.playwright = await async_playwright().start()
|
69
67
|
# 创建用户数据目录路径
|
70
68
|
user_data_dir = os.path.join(os.path.expanduser("~"), ".playwright_user_data")+f'{random.randint(1, 1000000)}'
|
71
69
|
os.makedirs(user_data_dir, exist_ok=True)
|
@@ -106,7 +104,6 @@ class WebSearcher:
|
|
106
104
|
user_data_dir=user_data_dir,
|
107
105
|
**context_options
|
108
106
|
)
|
109
|
-
|
110
107
|
self.browser = None # 不再需要单独的browser引用
|
111
108
|
|
112
109
|
except Exception as e:
|
@@ -148,7 +145,6 @@ class WebSearcher:
|
|
148
145
|
|
149
146
|
except Exception as e:
|
150
147
|
logger.error(f"Failed to initialize WebSearcher: {e}")
|
151
|
-
await self.close()
|
152
148
|
raise
|
153
149
|
|
154
150
|
async def simulate_human_scroll(self, page):
|
@@ -260,7 +256,6 @@ class WebSearcher:
|
|
260
256
|
wait_until='load',
|
261
257
|
timeout=timeout * 1000
|
262
258
|
)
|
263
|
-
|
264
259
|
# 使用搜索引擎特定的选择器
|
265
260
|
results = None
|
266
261
|
|
@@ -268,7 +263,7 @@ class WebSearcher:
|
|
268
263
|
if engine == 'google':
|
269
264
|
await self.simulate_human_scroll(page)
|
270
265
|
|
271
|
-
selector_timeout =
|
266
|
+
selector_timeout = timeout * 1000
|
272
267
|
for selector in engine_config['selectors']:
|
273
268
|
try:
|
274
269
|
logger.info(f"Trying selector: {selector}")
|
@@ -297,7 +292,7 @@ class WebSearcher:
|
|
297
292
|
await self.simulate_human_scroll(page)
|
298
293
|
|
299
294
|
# 重新尝试所有选择器
|
300
|
-
selector_timeout =
|
295
|
+
selector_timeout = timeout * 1000
|
301
296
|
for selector in engine_config['selectors']:
|
302
297
|
try:
|
303
298
|
logger.info(f"Retrying selector: {selector}")
|
@@ -342,12 +337,8 @@ class WebSearcher:
|
|
342
337
|
logger.error(f"Search failed - Query: {query} - Error: {e}", exc_info=True)
|
343
338
|
return f"搜索失败: {str(e)}"
|
344
339
|
finally:
|
345
|
-
|
346
|
-
|
347
|
-
logger.debug("context.close")
|
348
|
-
await context.close()
|
349
|
-
except Exception as e:
|
350
|
-
logger.error(f"Error closing page: {e}")
|
340
|
+
await self.close()
|
341
|
+
|
351
342
|
|
352
343
|
async def close(self):
|
353
344
|
"""关闭浏览器"""
|
@@ -490,8 +481,4 @@ class WebSearcher:
|
|
490
481
|
logger.error(f"抖音视频搜索失败 - 关键词: {keyword} - 错误: {e}", exc_info=True)
|
491
482
|
return f"搜索失败: {str(e)}"
|
492
483
|
finally:
|
493
|
-
|
494
|
-
try:
|
495
|
-
await context.close()
|
496
|
-
except Exception as e:
|
497
|
-
logger.error(f"关闭页面错误: {e}")
|
484
|
+
await self.close()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|