2025-09-25 11:42:04 +00:00
|
|
|
import time
|
|
|
|
|
import random
|
|
|
|
|
from selenium import webdriver
|
|
|
|
|
from selenium.webdriver.chrome.service import Service
|
|
|
|
|
import os
|
|
|
|
|
api_info = {
|
2025-10-12 05:43:20 +00:00
|
|
|
"model": os.environ.get("API_MODEL", "glm-4.5"), # 默认值可选
|
|
|
|
|
"base_url": os.environ.get("API_BASE_URL", "https://open.bigmodel.cn/api/paas/v4"),
|
|
|
|
|
"api_key": os.environ.get("API_KEY", ""),
|
2025-09-25 11:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# chrome浏览器以及驱动配置
|
|
|
|
|
CHROME_BINARY_PATH = os.environ.get("CHROME_BINARY_PATH", "/usr/bin/google-chrome")
|
|
|
|
|
CHROMEDRIVER_PATH = os.environ.get("CHROMEDRIVER_PATH", "/usr/local/bin/chromedriver")
|
|
|
|
|
# 最大并发数
|
|
|
|
|
MAX_CONCURRENT_BROWSERS = 3
|
|
|
|
|
|
|
|
|
|
#创建浏览器driver
|
|
|
|
|
def create_browser():
|
|
|
|
|
options = webdriver.ChromeOptions()
|
|
|
|
|
options.binary_location = CHROME_BINARY_PATH
|
|
|
|
|
# 每个实例随机调试端口
|
|
|
|
|
options.add_argument(f"--remote-debugging-port={random.randint(9222, 9322)}")
|
|
|
|
|
# options.add_argument("--headless=new")
|
|
|
|
|
options.add_argument("--disable-gpu")
|
|
|
|
|
options.add_argument("--disable-software-rasterizer")
|
|
|
|
|
options.add_argument("--no-sandbox")
|
|
|
|
|
options.add_argument("--disable-setuid-sandbox")
|
|
|
|
|
options.add_argument("--window-size=1920,1080")
|
|
|
|
|
options.add_argument("--disable-dev-shm-usage")
|
|
|
|
|
options.add_argument("--disable-blink-features=AutomationControlled")
|
|
|
|
|
options.add_experimental_option("excludeSwitches", ["enable-automation"])
|
|
|
|
|
options.add_experimental_option("useAutomationExtension", False)
|
|
|
|
|
prefs = {
|
|
|
|
|
"download.prompt_for_download": False,
|
|
|
|
|
"plugins.always_open_pdf_externally": True,
|
|
|
|
|
"profile.default_content_setting_values.automatic_downloads": 1,
|
|
|
|
|
"safebrowsing.enabled": True,
|
|
|
|
|
"safebrowsing.disable_download_protection": True
|
|
|
|
|
}
|
|
|
|
|
options.add_experimental_option("prefs", prefs)
|
|
|
|
|
return webdriver.Chrome(service=Service(CHROMEDRIVER_PATH), options=options)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _scroll_into_view(driver, el):
|
|
|
|
|
try:
|
|
|
|
|
driver.execute_script("arguments[0].scrollIntoView({block:'center', inline:'center'});", el)
|
|
|
|
|
time.sleep(0.2)
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|