botasaurus
botasaurus copied to clipboard
tmp files consuming lot of disk space
I am running botasaurus with chromium with the following settings
@browser(
output=None,
create_error_logs=False,
headless=True,
close_on_crash=True,
block_images=True,
add_arguments=[
"--no-sandbox",
"--allow-insecure-localhost",
"--disable-web-security",
"--disable-features=IsolateOrigins,site-per-process",
"--disable-blink-features=AutomationControlled",
"--disable-crash-reporter",
"--disable-breakpad",
],
raise_exception=True,
user_agent=dynamic_user_agent,
window_size=WindowSize.RANDOM,
wait_for_complete_page_load=False,
)
i am running multiple windows at the same time.
it is saving lot of temp files in this pattern /tmp/snap-private-tmp/snap.chromium/tmp/bota/.....
and with time it is leading to disk space fully consumed.
how can I avoid this issue?
You can change the default profile storage location to another directory, or create multiple profiles and switch between them as needed.
funcation get_profile()
def get_program_dir() -> Path:
# Get the application directory path to save the 'profiles' folder next to the program
if getattr(sys, "frozen", False):
return Path(sys.executable).parent
return Path(__file__).parent
def ensure_profiles_folder(base_dir: Optional[str] = None) -> Path:
base = Path(base_dir) if base_dir else get_program_dir()
profiles = base / "profiles"
profiles.mkdir(parents=True, exist_ok=True)
return profiles
def get_profile(data: Any, base_dir: Optional[str] = None) -> Optional[str]:
try:
if isinstance(data, dict):
phone = data.get("phone_number") or data.get("sender_phone")
if not phone:
return None
safe = profile_name
profiles_dir = ensure_profiles_folder(base_dir)
profile_path = profiles_dir / safe
profile_path.mkdir(parents=True, exist_ok=True)
print(f"✅ Using profile path: {profile_path}")
return str(profile_path.resolve())
except Exception as e:
print(f"⚠️ Error in get_profile: {e}")
return None
def _start_driver_for():
profile_path = get_profile(data_item)
print(profile_path)
drv = Driver(profile=profile_path) if profile_path else Driver()