once url copied from post, open that url and also show in log from selenium import…
- User
once url copied from post, open that url and also show in log
from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.chrome.options import Options from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import TimeoutException import time import json import yaml # Import yaml to load settings properly import os # Import os to work with file paths import logging import pyperclip # Import pyperclip to handle clipboard operations
Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') logger = logging.getLogger(name)
Suppress unnecessary log messages
os.environ['WDM_LOG_LEVEL'] = '0'
def normalize_cookie(cookie): # Ensure all required fields are present and format is compatible with Selenium required_fields = ["name", "value", "domain", "path"] normalized = {key: cookie.get(key, '') for key in required_fields}
code# Convert expirationDate to expiry for Selenium compatibility if "expirationDate" in cookie: normalized["expiry"] = int(cookie["expirationDate"]) # Set default secure and httpOnly values normalized["secure"] = cookie.get("secure", True) normalized["httpOnly"] = cookie.get("httpOnly", False) # Normalize sameSite values to match Selenium expectations same_site = cookie.get("sameSite", '').lower() if same_site in ["no_restriction", "unspecified"]: normalized["sameSite"] = "None" elif same_site in ["strict", "lax", "none"]: normalized["sameSite"] = same_site.capitalize() else: normalized["sameSite"] = "None" # Default to 'None' if value is invalid return normalizeddef load_settings(): # Load settings from YAML file logger.info("Loading settings from YAML file...") script_dir = os.path.dirname(os.path.abspath(file)) settings_path = os.path.join(script_dir, 'settings.yaml') if os.path.exists(settings_path): with open(settings_path, 'r') as file: settings_data = yaml.safe_load(file) logger.info("Settings loaded successfully.") return settings_data else: raise FileNotFoundError("Settings file not found. Please ensure settings.yaml exists.")
- Assistant
- User
once copied, check if that url already in file, if yes, go to next url if not open that url
for going next url, just increase post_no_element by 1.
- Assistant
- User
once checked in url file, if url there in file, log Comment was already there from me, I will do next
also, if not url not there, open and log as well
- Assistant
- User
if there is comment already, dont increase no_of_post , keep it as it is
- Assistant