36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
# 移除 app.py 中的 Selenium 相关代码
|
|
|
|
with open('app.py', 'r', encoding='utf-8') as f:
|
|
lines = f.readlines()
|
|
|
|
# 定义要删除的行范围(包含开始和结束)
|
|
# get_articles_with_selenium_api: 451-665
|
|
# get_articles_with_selenium: 666-1038
|
|
# _extract_articles_from_page: 1093-1211
|
|
|
|
delete_ranges = [
|
|
(451, 665), # get_articles_with_selenium_api
|
|
(666, 1038), # get_articles_with_selenium
|
|
(1093, 1211) # _extract_articles_from_page
|
|
]
|
|
|
|
output_lines = []
|
|
for i, line in enumerate(lines, 1):
|
|
should_keep = True
|
|
for start, end in delete_ranges:
|
|
if start <= i <= end:
|
|
should_keep = False
|
|
break
|
|
if should_keep:
|
|
output_lines.append(line)
|
|
|
|
with open('app_refactored.py', 'w', encoding='utf-8') as f:
|
|
f.writelines(output_lines)
|
|
|
|
print(f"✅ 原始行数: {len(lines)}")
|
|
print(f"✅ 删除后行数: {len(output_lines)}")
|
|
print(f"✅ 已删除: {len(lines) - len(output_lines)} 行")
|
|
print(f"✅ 新文件已保存为: app_refactored.py")
|
|
|