ai客服
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
3.5 KiB

1 month ago
  1. import sys
  2. def refine_scroll():
  3. with open('/Users/getmind/ds/kf/erp_automation.py', 'r') as f:
  4. content = f.read()
  5. # Place 1: scroll logic in step E2
  6. old_scroll_logic = """ try:
  7. # 聚水潭的滚动容器通常是 #_jt_body
  8. scroll_target = table_frame.locator("#_jt_body")
  9. if scroll_target.count() > 0:
  10. scroll_target.first.evaluate("el => el.scrollTop += 800")
  11. time.sleep(1)
  12. else:
  13. break
  14. except:
  15. break"""
  16. new_scroll_logic = """ try:
  17. scroll_target = table_frame.locator("#_jt_body")
  18. if scroll_target.count() > 0:
  19. # 每次向下滚动 400 像素,避免滚得太快跳过中间的数据
  20. scroll_target.first.evaluate("el => el.scrollTop += 400")
  21. time.sleep(1.5) # 给一点时间让虚拟列表渲染 DOM
  22. else:
  23. break
  24. except:
  25. break"""
  26. # Also fix the break logic
  27. old_break = """ if new_rows_in_view == 0 and scroll_round > 0:
  28. # 没有发现新行,说明到底了
  29. break"""
  30. new_break = """ if new_rows_in_view == 0 and scroll_round > 0:
  31. # 给最后一次机会,再等0.5秒检查一下
  32. time.sleep(0.5)
  33. rows_after_wait = table_frame.locator("._jt_row").count()
  34. if rows_after_wait == 0 or rows_after_wait <= len(processed_indices):
  35. break"""
  36. content = content.replace(old_scroll_logic, new_scroll_logic)
  37. content = content.replace(old_break, new_break)
  38. # Place 2: scroll logic in step E10
  39. old_scroll_logic_2 = """ try:
  40. scroll_target = table_frame.locator("#_jt_body")
  41. if scroll_target.count() > 0:
  42. scroll_target.first.evaluate("el => el.scrollTop += 800")
  43. time.sleep(1)
  44. else:
  45. break
  46. except:
  47. break"""
  48. new_scroll_logic_2 = """ try:
  49. scroll_target = table_frame.locator("#_jt_body")
  50. if scroll_target.count() > 0:
  51. scroll_target.first.evaluate("el => el.scrollTop += 400")
  52. time.sleep(1.5)
  53. else:
  54. break
  55. except:
  56. break"""
  57. content = content.replace(old_scroll_logic_2, new_scroll_logic_2)
  58. with open('/Users/getmind/ds/kf/erp_automation.py', 'w') as f:
  59. f.write(content)
  60. if __name__ == '__main__':
  61. refine_scroll()