|
|
- import sys
-
- def refine_scroll():
- with open('/Users/getmind/ds/kf/erp_automation.py', 'r') as f:
- content = f.read()
-
- # Place 1: scroll logic in step E2
- old_scroll_logic = """ try:
- # 聚水潭的滚动容器通常是 #_jt_body
- scroll_target = table_frame.locator("#_jt_body")
- if scroll_target.count() > 0:
- scroll_target.first.evaluate("el => el.scrollTop += 800")
- time.sleep(1)
- else:
- break
- except:
- break"""
-
- new_scroll_logic = """ try:
- scroll_target = table_frame.locator("#_jt_body")
- if scroll_target.count() > 0:
- # 每次向下滚动 400 像素,避免滚得太快跳过中间的数据
- scroll_target.first.evaluate("el => el.scrollTop += 400")
- time.sleep(1.5) # 给一点时间让虚拟列表渲染 DOM
- else:
- break
- except:
- break"""
-
- # Also fix the break logic
- old_break = """ if new_rows_in_view == 0 and scroll_round > 0:
- # 没有发现新行,说明到底了
- break"""
-
- new_break = """ if new_rows_in_view == 0 and scroll_round > 0:
- # 给最后一次机会,再等0.5秒检查一下
- time.sleep(0.5)
- rows_after_wait = table_frame.locator("._jt_row").count()
- if rows_after_wait == 0 or rows_after_wait <= len(processed_indices):
- break"""
-
- content = content.replace(old_scroll_logic, new_scroll_logic)
- content = content.replace(old_break, new_break)
-
- # Place 2: scroll logic in step E10
- old_scroll_logic_2 = """ try:
- scroll_target = table_frame.locator("#_jt_body")
- if scroll_target.count() > 0:
- scroll_target.first.evaluate("el => el.scrollTop += 800")
- time.sleep(1)
- else:
- break
- except:
- break"""
-
- new_scroll_logic_2 = """ try:
- scroll_target = table_frame.locator("#_jt_body")
- if scroll_target.count() > 0:
- scroll_target.first.evaluate("el => el.scrollTop += 400")
- time.sleep(1.5)
- else:
- break
- except:
- break"""
-
- content = content.replace(old_scroll_logic_2, new_scroll_logic_2)
-
- with open('/Users/getmind/ds/kf/erp_automation.py', 'w') as f:
- f.write(content)
-
- if __name__ == '__main__':
- refine_scroll()
|