Update main.py
Browse files
main.py
CHANGED
@@ -16,6 +16,7 @@ import os
|
|
16 |
import re
|
17 |
import threading
|
18 |
from DrissionPage import ChromiumPage, ChromiumOptions
|
|
|
19 |
import logging
|
20 |
from dotenv import load_dotenv
|
21 |
|
@@ -29,6 +30,10 @@ logging.basicConfig(
|
|
29 |
)
|
30 |
logger = logging.getLogger(__name__)
|
31 |
|
|
|
|
|
|
|
|
|
32 |
# 修改全局数据存储
|
33 |
global_data = {
|
34 |
"cookie": None,
|
@@ -59,10 +64,40 @@ def get_cookie():
|
|
59 |
try:
|
60 |
logger.info("Starting cookie retrieval process...")
|
61 |
|
62 |
-
#
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
logger.info("Navigating to target website...")
|
68 |
page.get("https://chat.akash.network/")
|
|
|
16 |
import re
|
17 |
import threading
|
18 |
from DrissionPage import ChromiumPage, ChromiumOptions
|
19 |
+
from DrissionPage.common import Settings
|
20 |
import logging
|
21 |
from dotenv import load_dotenv
|
22 |
|
|
|
30 |
)
|
31 |
logger = logging.getLogger(__name__)
|
32 |
|
33 |
+
# 全局配置 DrissionPage 设置
|
34 |
+
Settings.set_browser_connect_timeout(60) # 增加连接超时时间
|
35 |
+
Settings.set_language('en') # 设置错误信息为英文,方便调试
|
36 |
+
|
37 |
# 修改全局数据存储
|
38 |
global_data = {
|
39 |
"cookie": None,
|
|
|
64 |
try:
|
65 |
logger.info("Starting cookie retrieval process...")
|
66 |
|
67 |
+
# 创建配置对象
|
68 |
+
options = ChromiumOptions()
|
69 |
+
|
70 |
+
# 设置浏览器路径
|
71 |
+
chrome_path = os.getenv('CHROME_PATH', '/usr/bin/google-chrome-stable')
|
72 |
+
logger.info(f"Using Chrome path: {chrome_path}")
|
73 |
+
options.set_browser_path(chrome_path)
|
74 |
+
|
75 |
+
# 设置用户数据目录
|
76 |
+
user_data_dir = os.getenv('CHROME_USER_DATA_DIR', '/tmp/chrome-data')
|
77 |
+
logger.info(f"Using user data directory: {user_data_dir}")
|
78 |
+
options.set_user_data_dir(user_data_dir) # 使用正确的方法设置用户数据目录
|
79 |
+
|
80 |
+
# 设置无头模式和其他参数
|
81 |
+
options.set_headless(True) # 使用 DrissionPage 提供的方法设置无头模式
|
82 |
+
options.set_argument('--no-sandbox')
|
83 |
+
options.set_argument('--disable-dev-shm-usage')
|
84 |
+
options.set_argument('--disable-gpu')
|
85 |
+
options.set_argument('--disable-software-rasterizer')
|
86 |
+
options.set_argument('--disable-extensions')
|
87 |
+
options.set_argument('--disable-setuid-sandbox')
|
88 |
+
options.set_argument('--no-first-run')
|
89 |
+
options.set_argument('--no-zygote')
|
90 |
+
options.set_argument('--single-process')
|
91 |
+
options.set_argument('--window-size=1920,1080')
|
92 |
+
options.set_argument('--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36')
|
93 |
+
|
94 |
+
# 启用详细日志
|
95 |
+
options.set_argument('--enable-logging')
|
96 |
+
options.set_argument('--v=1')
|
97 |
+
|
98 |
+
# 使用配置对象创建页面
|
99 |
+
logger.info("Creating ChromiumPage instance...")
|
100 |
+
page = ChromiumPage(options)
|
101 |
|
102 |
logger.info("Navigating to target website...")
|
103 |
page.get("https://chat.akash.network/")
|