Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,26 @@
|
|
| 1 |
from playwright.sync_api import sync_playwright
|
| 2 |
import os, time, random
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def auto_read():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
with sync_playwright() as p:
|
| 6 |
browser = p.chromium.launch()
|
| 7 |
page = browser.new_page()
|
|
@@ -22,6 +41,9 @@ def auto_read():
|
|
| 22 |
page.mouse.wheel(0, random.randint(200,500))
|
| 23 |
time.sleep(random.uniform(1.5,4))
|
| 24 |
time.sleep(random.randint(600, 1200)) # 10-20分钟间隔
|
|
|
|
|
|
|
| 25 |
|
| 26 |
if __name__ == "__main__":
|
|
|
|
| 27 |
auto_read()
|
|
|
|
| 1 |
from playwright.sync_api import sync_playwright
|
| 2 |
import os, time, random
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
+
# 添加日志初始化
|
| 6 |
+
logging.basicConfig(
|
| 7 |
+
level=logging.INFO,
|
| 8 |
+
format='%(asctime)s [%(levelname)s] %(message)s',
|
| 9 |
+
handlers=[logging.StreamHandler()]
|
| 10 |
+
)
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
|
| 13 |
def auto_read():
|
| 14 |
+
logger.info("=== 程序启动 ===") # 启动标记
|
| 15 |
+
try:
|
| 16 |
+
with sync_playwright() as p:
|
| 17 |
+
logger.info("正在启动浏览器...")
|
| 18 |
+
browser = p.chromium.launch(
|
| 19 |
+
executable_path="/usr/bin/chromium",
|
| 20 |
+
args=["--disable-gpu", "--no-sandbox"]
|
| 21 |
+
)
|
| 22 |
+
# ...其余代码保持不变...
|
| 23 |
+
|
| 24 |
with sync_playwright() as p:
|
| 25 |
browser = p.chromium.launch()
|
| 26 |
page = browser.new_page()
|
|
|
|
| 41 |
page.mouse.wheel(0, random.randint(200,500))
|
| 42 |
time.sleep(random.uniform(1.5,4))
|
| 43 |
time.sleep(random.randint(600, 1200)) # 10-20分钟间隔
|
| 44 |
+
except Exception as e:
|
| 45 |
+
logger.error(f"致命错误: {str(e)}", exc_info=True)
|
| 46 |
|
| 47 |
if __name__ == "__main__":
|
| 48 |
+
logger.info("开始执行主函数")
|
| 49 |
auto_read()
|