chatgpt-mirai-qq-bot-web-search 0.2.6__py3-none-any.whl → 0.2.7__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chatgpt-mirai-qq-bot-web-search
3
- Version: 0.2.6
3
+ Version: 0.2.7
4
4
  Summary: WebSearch adapter for lss233/chatgpt-mirai-qq-bot
5
5
  Home-page: https://github.com/chuanSir123/web_search
6
6
  Author: chuanSir
@@ -1,11 +1,11 @@
1
1
  web_search/__init__.py,sha256=bpu1gpf9tq3mOAoaGMM-8S6GBw2GzRAG6ClHGlp-CVw,4607
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=760WTBGusxYntigGi5Wsbm2rRHEWq3sTwfNlf3ew3b0,20919
4
+ web_search/web_searcher.py,sha256=Bgnc0HGXZkMULZ5BWCJxBUzLFew19LuTL7lmdeqmfWs,21384
5
5
  web_search/example/roleplayWithWebSearch.yaml,sha256=C-dGy3z8gcRcmxzurssP-kPRLqMf1TYR-nnNUaJjISE,7468
6
- chatgpt_mirai_qq_bot_web_search-0.2.6.dist-info/LICENSE,sha256=ILBn-G3jdarm2w8oOrLmXeJNU3czuJvVhDLBASWdhM8,34522
7
- chatgpt_mirai_qq_bot_web_search-0.2.6.dist-info/METADATA,sha256=88y-xtYK-se7dwVVU2_fcXx_rGCUEgIxWMJvjI4Dfwg,1734
8
- chatgpt_mirai_qq_bot_web_search-0.2.6.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
9
- chatgpt_mirai_qq_bot_web_search-0.2.6.dist-info/entry_points.txt,sha256=o3kRDSdSmSdnCKlK6qS57aN0WpI4ab-Nxub2NwUrjf0,64
10
- chatgpt_mirai_qq_bot_web_search-0.2.6.dist-info/top_level.txt,sha256=PoNm8MJYw_y8RTMaNlY0ePLoNHxVUAE2IHDuL5fFubI,11
11
- chatgpt_mirai_qq_bot_web_search-0.2.6.dist-info/RECORD,,
6
+ chatgpt_mirai_qq_bot_web_search-0.2.7.dist-info/LICENSE,sha256=ILBn-G3jdarm2w8oOrLmXeJNU3czuJvVhDLBASWdhM8,34522
7
+ chatgpt_mirai_qq_bot_web_search-0.2.7.dist-info/METADATA,sha256=88N33AlLdzPyW0GtLU8eDH0qGEKbqmHpl0UYooIU2-E,1734
8
+ chatgpt_mirai_qq_bot_web_search-0.2.7.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
9
+ chatgpt_mirai_qq_bot_web_search-0.2.7.dist-info/entry_points.txt,sha256=o3kRDSdSmSdnCKlK6qS57aN0WpI4ab-Nxub2NwUrjf0,64
10
+ chatgpt_mirai_qq_bot_web_search-0.2.7.dist-info/top_level.txt,sha256=PoNm8MJYw_y8RTMaNlY0ePLoNHxVUAE2IHDuL5fFubI,11
11
+ chatgpt_mirai_qq_bot_web_search-0.2.7.dist-info/RECORD,,
@@ -268,10 +268,12 @@ class WebSearcher:
268
268
  if engine == 'google':
269
269
  await self.simulate_human_scroll(page)
270
270
 
271
+ timeout = 5000
271
272
  for selector in engine_config['selectors']:
272
273
  try:
273
274
  logger.info(f"Trying selector: {selector}")
274
- await page.wait_for_selector(selector, timeout=8000) # 增加等待时间
275
+ await page.wait_for_selector(selector, timeout=timeout) # 增加等待时间
276
+ timeout = 500
275
277
  results = await page.query_selector_all(selector)
276
278
  if results and len(results) > 0:
277
279
  logger.info(f"Found {len(results)} results with selector {selector}")
@@ -281,28 +283,36 @@ class WebSearcher:
281
283
  continue
282
284
 
283
285
  if not results:
284
- # 尝试直接使用 JavaScript 获取元素
285
- if engine == 'google':
286
- try:
287
- # 使用更通用的JavaScript选择器尝试获取结果
288
- results = await page.evaluate("""
289
- () => {
290
- const elements = document.querySelectorAll('div[data-sokoban-container], div.g, .MjjYud');
291
- return Array.from(elements).length;
292
- }
293
- """)
294
- logger.info(f"JavaScript found {results} elements")
295
-
296
- # 如果找到了元素,使用evaluate来处理它们
297
- if results > 0:
298
- # 自定义处理逻辑...
299
- pass
300
- except Exception as e:
301
- logger.error(f"JavaScript evaluation failed: {e}")
302
-
303
- logger.error("No search results found with any selector")
304
- await page.screenshot(path=f'search_failed_{engine}.png')
305
- return "搜索结果加载失败"
286
+ # 添加重试机制
287
+ retry_count = 0
288
+ while not results and retry_count < max_results:
289
+ logger.info(f"Retrying search, attempt {retry_count + 1}/{max_results}")
290
+ # 刷新页面重试
291
+ await page.reload(wait_until='load', timeout=timeout * 1000)
292
+ await self.simulate_human_scroll(page)
293
+
294
+ # 重新尝试所有选择器
295
+ timeout = 5000
296
+ for selector in engine_config['selectors']:
297
+ try:
298
+ logger.info(f"Retrying selector: {selector}")
299
+ await page.wait_for_selector(selector, timeout=timeout)
300
+ timeout = 500
301
+ results = await page.query_selector_all(selector)
302
+ if results and len(results) > 0:
303
+ logger.info(f"Found {len(results)} results with selector {selector} on retry {retry_count + 1}")
304
+ break
305
+ except Exception as e:
306
+ logger.warning(f"Selector {selector} failed on retry {retry_count + 1}: {e}")
307
+ continue
308
+
309
+ retry_count += 1
310
+
311
+
312
+ # 如果所有重试都失败了,才返回错误
313
+ if not results:
314
+ logger.error("No search results found after all retries")
315
+ return "搜索结果加载失败"
306
316
 
307
317
  logger.info(f"Found {len(results)} search results")
308
318