Guest User

Untitled

a guest
Feb 6th, 2026
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 30.20 KB | Source Code | 0 0
  1.  
  2.  
  3. import json
  4. import random
  5. import time
  6. import logging
  7. import threading
  8. from urllib.parse import urljoin
  9. from colorama import Fore, init
  10. import pystyle
  11. from seleniumwire import webdriver
  12. import undetected_chromedriver as uc
  13. from selenium.webdriver.common.by import By
  14. from selenium.webdriver.common.action_chains import ActionChains
  15. from selenium.webdriver.common.keys import Keys
  16. from selenium.webdriver.support.ui import WebDriverWait
  17. from selenium.webdriver.support import expected_conditions as EC
  18. from selenium.common.exceptions import StaleElementReferenceException, NoSuchElementException, InvalidSessionIdException, WebDriverException, MoveTargetOutOfBoundsException, ElementNotInteractableException
  19.  
  20. init(autoreset=True)
  21.  
  22. # ====================== LOGGING ======================
  23. logging.basicConfig(
  24.     level=logging.INFO,
  25.     format='%(asctime)s | %(levelname)s | %(message)s',
  26.     handlers=[
  27.         logging.FileHandler('mega_bot.log', encoding='utf-8'),
  28.         logging.StreamHandler()
  29.     ]
  30. )
  31.  
  32. # ====================== CONFIG YÜKLE ======================
  33. try:
  34.     with open('config.json', 'r', encoding='utf-8') as f:
  35.         config = json.load(f)
  36. except FileNotFoundError:
  37.     logging.critical("config.json bulunamadı!")
  38.     exit(1)
  39.  
  40. # ====================== GLOBAL ======================
  41. proxy_pool = config.get("proxy_list", [])
  42. domains = config.get("domains", [config.get("domain", "")])  # domains yoksa domain'ı liste yap
  43. ga_code = config["ga4_code"]
  44. proxy_lock = threading.Lock()
  45. current_proxy_index = 0
  46. banned_proxies = set()  # Başarısız proxy'leri geçici olarak banla
  47. min_wait_success = config.get("min_wait_success", 60)
  48. max_wait_success = config.get("max_wait_success", 300)
  49.  
  50. # ====================== BANNER ======================
  51. def banner():
  52.     print(pystyle.Colorate.Vertical(pystyle.Colors.blue_to_cyan, f"""
  53.    ╔═══════════════════════════════════════════════════════════════╗
  54.    ║       MEGA ORGANİK BOT v20.9 – 5-15 DK | 16+ DAVRANIŞ         ║
  55.    ║        Siteler: {', '.join(domains[:3])}... | {len(domains)} Domain   ║
  56.    ║     SCROLL | HOVER | CLICK | BACK | TAB | FORM | VIDEO | IMG  ║
  57.    ║         ZOOM | COPY | RIGHT-CLICK | REFRESH | SEARCH | GA4    ║
  58.    ║         + 404/403 TESPİT | SITEMAP FİLTRE | RETRY | SAFE-FILT ║
  59.    ║         + MOBILE SWIPE | MOUSE MOVE | TEXT SELECT | PINCH ZOOM║
  60.    ║                | DOUBLE CLICK | WHEEL SCROLL | SAFE QUIT      ║
  61.    ║                | TÜRK USER AGENT | %100 TR TRAFİK             ║
  62.    ║                | KEYBOARD INPUT | BOTTOM SCROLL | EXTRA HOVER ║
  63.    ║                | SAFE OFFSET | INTERACT CHECK | EXTRA RETRY   ║
  64.    ║                | MOBILE %90 | BACKOFF SLEEP                   ║
  65.    ╚═══════════════════════════════════════════════════════════════╝
  66.    """))
  67.     print(f"{Fore.GREEN}Bot başlatılıyor... [{config.get('threads', 1)} thread]{Fore.RESET}\n")
  68.  
  69. # ====================== PROXY ROTASYONU ======================
  70. def get_next_proxy():
  71.     global current_proxy_index
  72.     with proxy_lock:
  73.         if not proxy_pool:
  74.             logging.warning("Proxy yok → Direkt bağlantı")
  75.             return None, None
  76.         available_proxies = [p for i, p in enumerate(proxy_pool) if i not in banned_proxies]
  77.         if not available_proxies:
  78.             banned_proxies.clear()  # Tümünü sıfırla eğer hepsi banlandıysa
  79.             available_proxies = proxy_pool
  80.         proxy = available_proxies[current_proxy_index % len(available_proxies)]
  81.         current_proxy_index += 1
  82.         user = proxy["user"]
  83.         password = proxy["pass"]
  84.         host = proxy["host"]
  85.         port = proxy["port"]
  86.         proxy_url = f"http://{user}:{password}@{host}:{port}"
  87.         logging.info(f"{Fore.CYAN}Yeni Proxy → {host}:{port}{Fore.RESET}")
  88.         return proxy_url, proxy
  89.  
  90. # ====================== USER AGENT GENERATOR ======================
  91. def generate_user_agent():
  92.     is_mobile = random.random() < 0.9  # Mobil yoğunluğu %90'a çıkarıldı
  93.  
  94.     if is_mobile:
  95.         screen_res = random.choice(["360x740", "375x812", "414x896", "390x844", "412x915", "480x853", "320x568", "411x823", "360x640", "768x1024"])
  96.         platform = random.choice(["Android", "iOS"])
  97.         browser = random.choice(["Chrome Mobile", "Mobile Safari", "Samsung Internet", "Opera Mini", "UC Browser", "QQ Browser",
  98.                                   "Baidu Browser", "Firefox Mobile", "Edge Mobile", "DuckDuckGo Browser", "Puffin Browser",
  99.                                   "Vivaldi Mobile", "Brave Mobile", "Yandex Browser Mobile", "Naver Whale"])
  100.     else:
  101.         screen_res = random.choice(["1920x1080", "1366x768", "1536x864", "2560x1440", "3840x2160", "1440x900", "1280x720"])
  102.         platform = random.choice(["Windows", "MacOS", "Linux", "ChromeOS", "FreeBSD", "OpenBSD", "Solaris", "Haiku"])
  103.         browser = random.choice(["Chrome", "Firefox", "Safari", "Edge", "Opera", "Brave", "Vivaldi", "Tor Browser", "Waterfox",
  104.                                   "Pale Moon", "SeaMonkey", "Samsung Internet Browser", "UC Browser", "Yandex Browser",
  105.                                   "Epic Privacy Browser", "Maxthon", "SlimBrowser", "Avant Browser", "K-Meleon", "Lunascape"])
  106.  
  107.     # Türk odaklı user agent oluştur
  108.     if platform == "Android":
  109.         ua = f"Mozilla/5.0 (Linux; Android {random.randint(10, 15)}; {random.choice(['SM-G', 'Pixel', 'Redmi', 'Pocophone', 'Huawei', 'Oppo'])} Build/{random.choice(['QP1A', 'RKQ1', 'SKQ1'])}) AppleWebKit/537.36 (KHTML, like Gecko) {browser}/{random.randint(100, 120)}.0 Mobile Safari/537.36"
  110.     elif platform == "iOS":
  111.         ua = f"Mozilla/5.0 (iPhone; CPU iPhone OS {random.randint(15, 18)}_{random.randint(0, 5)} like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/{random.randint(15, 18)}.0 Mobile/15E148 Safari/604.1"
  112.     elif platform == "Windows":
  113.         ua = f"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) {browser}/{random.randint(100, 120)}.0 Safari/537.36"
  114.     elif platform == "MacOS":
  115.         ua = f"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_{random.randint(13, 15)}_{random.randint(0, 6)}) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/{random.randint(13, 15)}.1.15 Safari/605.1.15"
  116.     else:
  117.         ua = f"Mozilla/5.0 (X11; {platform}; x86_64) AppleWebKit/537.36 (KHTML, like Gecko) {browser}/{random.randint(100, 120)}.0 Safari/537.36"
  118.  
  119.     logging.info(f"{Fore.CYAN}User Agent: {ua}{Fore.RESET}")
  120.     return ua
  121.  
  122. # ====================== DRIVER ======================
  123. def create_stealth_driver(proxy_url=None):
  124.     options = uc.ChromeOptions()
  125.     options.add_argument('--no-sandbox')
  126.     options.add_argument('--disable-dev-shm-usage')
  127.     options.add_argument('--lang=tr-TR,tr')
  128.     options.add_argument('--window-size=390,844')
  129.     options.add_argument('--disable-blink-features=AutomationControlled')
  130.     options.add_argument('--disable-gpu')
  131.     options.add_argument('--ignore-certificate-errors')
  132.     options.add_argument('--disable-extensions')
  133.     options.add_argument('--disable-plugins')
  134.     options.add_argument('--disable-images')
  135.  
  136.     seleniumwire_options = {}
  137.     if proxy_url:
  138.         seleniumwire_options = {
  139.             'proxy': {
  140.                 'http': proxy_url,
  141.                 'https': proxy_url,
  142.                 'no_proxy': 'localhost,127.0.0.1'
  143.             }
  144.         }
  145.  
  146.     prefs = {
  147.         "profile.default_content_setting_values.notifications": 2,
  148.         "profile.managed_default_content_settings.images": 2
  149.     }
  150.     options.add_experimental_option("prefs", prefs)
  151.  
  152.     for attempt in range(1):
  153.         try:
  154.             driver = uc.Chrome(
  155.                 options=options,
  156.                 seleniumwire_options=seleniumwire_options if proxy_url else None,
  157.                 headless=config.get("headless", True),
  158.                 version_main=config.get("chrome_version", 141)
  159.             )
  160.             driver.implicitly_wait(15)
  161.  
  162.             ua = generate_user_agent()  # Rastgele Türk user agent
  163.             driver.execute_cdp_cmd("Network.setUserAgentOverride", {"userAgent": ua})
  164.             driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
  165.             driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
  166.                 "source": """
  167.                    Object.defineProperty(navigator, 'webdriver', {get: () => undefined});
  168.                    Object.defineProperty(navigator, 'hardwareConcurrency', {get: () => Math.floor(Math.random() * 8) + 2});
  169.                    Object.defineProperty(navigator, 'maxTouchPoints', {get: () => Math.floor(Math.random() * 3) + 1});
  170.                    Object.defineProperty(navigator, 'languages', {get: () => ['tr-TR', 'tr', 'en-US', 'en']});
  171.                """
  172.             })
  173.             return driver
  174.         except Exception as e:
  175.             logging.error(f"Driver hatası: {e}")
  176.             time.sleep(5)
  177.     return None
  178.  
  179. # ====================== GERÇEK CAPTCHA TESPİT ======================
  180. def is_real_captcha(driver):
  181.     try:
  182.         if driver.find_elements(By.CSS_SELECTOR, "iframe[title='reCAPTCHA'], iframe[src*='recaptcha'], .g-recaptcha, #cf-wrapper"):
  183.             return True
  184.         url = driver.current_url.lower()
  185.         if any(x in url for x in ["consent.google.com", "challenges.cloudflare.com", "captcha", "verify", "interstitial"]):
  186.             return True
  187.         if driver.execute_script("""
  188.            return (
  189.                document.querySelector('div.g-recaptcha') !== null ||
  190.                document.querySelector('#recaptcha') !== null ||
  191.                document.querySelector('.cf-challenge-form') !== null ||
  192.                document.querySelector('#challenge-form') !== null
  193.            );
  194.        """):
  195.             return True
  196.     except: pass
  197.     return False
  198.  
  199. def handle_captcha_and_rotate(driver, proxy=None):
  200.     if "checking your browser" in driver.page_source.lower() or "yönlendiriliyorsunuz" in driver.page_source.lower() or "cloudflare" in driver.page_source.lower():
  201.         logging.info(f"{Fore.YELLOW}Kontrol ediliyor... 30s bekleniyor{Fore.RESET}")
  202.         time.sleep(30)
  203.         return False
  204.     if is_real_captcha(driver):
  205.         logging.warning(f"{Fore.RED}GERÇEK CAPTCHA → PROXY BANLANIYOR{Fore.RESET}")
  206.         if proxy:
  207.             proxy_index = proxy_pool.index(proxy)
  208.             banned_proxies.add(proxy_index)
  209.         try: driver.quit()
  210.         except: pass
  211.         time.sleep(10)  # Ban sonrası ekstra gecikme
  212.         return True
  213.     return False
  214.  
  215. # ====================== GA4 KONTROL ======================
  216. def is_ga4_tracked(driver):
  217.     try:
  218.         time.sleep(3)  # Daha uzun bekle
  219.         logs = driver.get_log('performance')
  220.         for log in logs:
  221.             msg = str(log['message'])
  222.             if 'google-analytics.com/g/collect' in msg and ga_code in msg:
  223.                 logging.info(f"{Fore.GREEN}GA4 HİT GÖRÜLDÜ!{Fore.RESET}")
  224.                 return True
  225.     except: pass
  226.     return False
  227.  
  228. # ====================== STATUS CODE KONTROL ======================
  229. def check_page_status(driver):
  230.     try:
  231.         requests = [req for req in driver.requests if req.url == driver.current_url and req.response]
  232.         if requests:
  233.             status = requests[-1].response.status_code
  234.             if status in [403, 404]:
  235.                 logging.warning(f"{Fore.RED}{status} HATASI TESPİT EDİLDİ → Ana sayfaya dönülüyor{Fore.RESET}")
  236.                 return True
  237.         # Alternatif: Sayfa içeriği kontrol
  238.         if "404" in driver.title or "Not Found" in driver.title or "404" in driver.page_source:
  239.             logging.warning(f"{Fore.RED}404 İÇERİK TESPİT EDİLDİ → Ana sayfaya dönülüyor{Fore.RESET}")
  240.             return True
  241.     except:
  242.         pass
  243.     return False
  244.  
  245. # ====================== RETRY WRAPPER ======================
  246. def find_elements_with_retry(driver, by, value, retries=3):
  247.     for _ in range(retries):
  248.         try:
  249.             return driver.find_elements(by, value)
  250.         except (StaleElementReferenceException, InvalidSessionIdException, WebDriverException):
  251.             logging.debug("Stale/Invalid/WebDriver element, retrying...")
  252.             time.sleep(1)
  253.     return []
  254.  
  255. def perform_action_with_retry(action_func, retries=3):
  256.     for _ in range(retries):
  257.         try:
  258.             action_func()
  259.             return True
  260.         except (StaleElementReferenceException, NoSuchElementException, InvalidSessionIdException, WebDriverException, MoveTargetOutOfBoundsException, ElementNotInteractableException):
  261.             logging.debug("Stale/NoSuch/Invalid/WebDriver/MoveOutOfBounds/NotInteractable element, retrying...")
  262.             time.sleep(1)
  263.     return False
  264.  
  265. # ====================== SAFE ELEMENT COLLECTOR ======================
  266. def safe_collect_elements(driver, by, value, filter_func=None):
  267.     elements = find_elements_with_retry(driver, by, value)
  268.     safe_elements = []
  269.     for elem in elements:
  270.         try:
  271.             if filter_func and not filter_func(elem):
  272.                 continue
  273.             # Ekstra check: Element interactable mı?
  274.             if elem.size['width'] > 0 and elem.size['height'] > 0 and elem.is_enabled():
  275.                 safe_elements.append(elem)
  276.         except StaleElementReferenceException:
  277.             continue
  278.     return safe_elements
  279.  
  280. # ====================== ULTRA İNSAN DAVRANIŞI (5-15 DK DÖNGÜ) ======================
  281. def ultra_human_loop(driver, selected_domain):
  282.     start_time = time.time()
  283.     max_duration = random.randint(300, 900)  # 5-15 dakika
  284.     visited_urls = set()
  285.     current_url = driver.current_url
  286.  
  287.     while time.time() - start_time < max_duration:
  288.         try:
  289.             remaining = int(max_duration - (time.time() - start_time))
  290.             logging.info(f"{Fore.CYAN}Kalan: {remaining}s | Sayfa: {current_url[:60]}...{Fore.RESET}")
  291.  
  292.             # Sayfa status kontrolü
  293.             if check_page_status(driver):
  294.                 driver.get(f"https://{selected_domain}")
  295.                 time.sleep(random.uniform(5, 10))
  296.                 current_url = driver.current_url
  297.                 del driver.requests  # Requestleri temizle
  298.                 continue
  299.  
  300.             # 1. SCROLL (Daha doğal, yavaş hızlar ekle)
  301.             for _ in range(random.randint(5, 12)):
  302.                 scroll_amount = random.randint(150, 800)
  303.                 driver.execute_script(f"window.scrollBy(0, {scroll_amount});")
  304.                 time.sleep(random.uniform(1.2, 4.5))
  305.                 if random.random() < 0.35:
  306.                     driver.execute_script(f"window.scrollBy(0, -{scroll_amount // 2});")
  307.                     time.sleep(random.uniform(0.8, 2.5))
  308.  
  309.             # Sayfa sonuna scroll (Yeni)
  310.             if random.random() < 0.3:
  311.                 driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
  312.                 time.sleep(random.uniform(3, 6))
  313.  
  314.             # 2. HOVER + CLICK (Daha fazla iç link, derin gezinme, sitemap filtre)
  315.             def link_filter(a):
  316.                 href = a.get_attribute("href")
  317.                 return (
  318.                     href and
  319.                     selected_domain in href and
  320.                     a.is_displayed() and
  321.                     href not in visited_urls and
  322.                     not any(x in href.lower() for x in ["javascript", "tel", "whatsapp", "mailto", "login", "logout", "sitemap", ".xml"]) and
  323.                     not href.lower().endswith('.xml')
  324.                 )
  325.  
  326.             internal_links = safe_collect_elements(driver, By.TAG_NAME, "a", link_filter)
  327.  
  328.             if internal_links:
  329.                 # Ekstra hover (Rastgele 2-4 link hover, süre varyasyonlu)
  330.                 for _ in range(random.randint(2, 4)):
  331.                     link_hover = random.choice(internal_links)
  332.                     ActionChains(driver).move_to_element(link_hover).pause(random.uniform(0.5, 2.5)).perform()
  333.                     time.sleep(random.uniform(0.3, 1.0))
  334.  
  335.                 link = random.choice(internal_links)
  336.                 def click_action():
  337.                     ActionChains(driver).move_to_element(link).pause(random.uniform(1.0, 3.0)).perform()
  338.                     time.sleep(random.uniform(1.5, 4.0))
  339.                     link.click()
  340.                 if perform_action_with_retry(click_action):
  341.                     time.sleep(random.uniform(10, 20))
  342.  
  343.                     new_url = driver.current_url
  344.                     if new_url != current_url:
  345.                         visited_urls.add(new_url)
  346.                         current_url = new_url
  347.                         is_ga4_tracked(driver)
  348.  
  349.                         # İç sayfada ekstra scroll ve gezinme
  350.                         for _ in range(random.randint(4, 8)):
  351.                             driver.execute_script(f"window.scrollBy(0, {random.randint(200, 700)});")
  352.                             time.sleep(random.uniform(2.0, 5.5))
  353.  
  354.                         # %25 geri dön
  355.                         if random.random() < 0.25:
  356.                             driver.back()
  357.                             time.sleep(random.uniform(5, 10))
  358.                             current_url = driver.current_url
  359.  
  360.             else:
  361.                 # Link yoksa rastgele bir iç sayfa seç (config'e ekleyebilirsiniz, yoksa ana sayfaya dön)
  362.                 logging.info(f"{Fore.YELLOW}Link yok → Rastgele iç sayfaya dönülüyor{Fore.RESET}")
  363.                 possible_paths = ["/blog", "/hakkinda", "/iletisim", "/urunler", "/hizmetler"]  # Örnek iç yollar, config'e ekleyin
  364.                 random_path = random.choice(possible_paths)
  365.                 driver.get(urljoin(f"https://{selected_domain}", random_path))
  366.                 time.sleep(8)
  367.                 current_url = driver.current_url
  368.  
  369.             # 3. FORM ETKİLEŞİMİ (Daha doğal typing, copy-paste ekle)
  370.             def input_filter(inp):
  371.                 return inp.is_displayed() and inp.is_enabled() and inp.size['width'] > 0 and inp.size['height'] > 0
  372.  
  373.             inputs = safe_collect_elements(driver, By.CSS_SELECTOR, "input[type='text'], input[type='search'], textarea", input_filter)
  374.             if inputs and random.random() < 0.45:
  375.                 inp = random.choice(inputs)
  376.                 def form_action():
  377.                     inp.click()
  378.                     inp.clear()
  379.                     text = "Örnek metin veya anahtar kelime"  # Rastgele metin, config'den çekebilirsiniz
  380.                     # Copy-paste simülasyonu
  381.                     if random.random() < 0.3:
  382.                         inp.send_keys(text)
  383.                     else:
  384.                         for char in text:  # Harf harf yaz
  385.                             inp.send_keys(char)
  386.                             time.sleep(random.uniform(0.08, 0.25))
  387.                     time.sleep(random.uniform(2.5, 5))
  388.                     if random.random() < 0.6:
  389.                         inp.send_keys(Keys.ENTER)  # Ara veya gönder
  390.                     else:
  391.                         inp.clear()
  392.                 perform_action_with_retry(form_action)
  393.  
  394.             # 4. VİDEO İZLEME (Play/pause, seek ekle)
  395.             def video_filter(vid):
  396.                 src = vid.get_attribute("src").lower()
  397.                 return "youtube" in src or "vimeo" in src
  398.  
  399.             videos = safe_collect_elements(driver, By.TAG_NAME, "iframe", video_filter)
  400.             if not videos:
  401.                 logging.debug(f"{Fore.YELLOW}Video içeriği yok, atlanıyor.{Fore.RESET}")
  402.             for vid in videos:
  403.                 if random.random() < 0.4:
  404.                     driver.execute_script("arguments[0].scrollIntoView();", vid)
  405.                     time.sleep(random.uniform(15, 40))  # Daha uzun izle
  406.                     # Simüle play/pause ve seek
  407.                     if random.random() < 0.6:
  408.                         def video_action():
  409.                             ActionChains(driver).move_to_element(vid).click().perform()
  410.                             time.sleep(random.uniform(10, 20))
  411.                             # Seek simülasyonu (ileri sar)
  412.                             ActionChains(driver).move_to_element(vid).key_down(Keys.ARROW_RIGHT).key_up(Keys.ARROW_RIGHT).perform()
  413.                             time.sleep(random.uniform(5, 15))
  414.                             ActionChains(driver).move_to_element(vid).click().perform()
  415.                         perform_action_with_retry(video_action)
  416.  
  417.             # 5. YENİ SEKME AÇ (Daha sık, birden fazla sekme)
  418.             if random.random() < 0.3 and internal_links:
  419.                 for _ in range(random.randint(1, 2)):  # 1-2 sekme
  420.                     link = random.choice(internal_links)
  421.                     driver.execute_script("window.open(arguments[0].href, '_blank');", link)
  422.                     driver.switch_to.window(driver.window_handles[-1])
  423.                     time.sleep(random.uniform(12, 25))
  424.                     is_ga4_tracked(driver)
  425.                     driver.close()
  426.                 driver.switch_to.window(driver.window_handles[0])
  427.  
  428.             # 6. SAYFA YENİLE (Daha doğal aralıklar)
  429.             if random.random() < 0.2:
  430.                 driver.refresh()
  431.                 time.sleep(random.uniform(7, 12))
  432.  
  433.             # 7. RESİM/BUTON ETKİLEŞİMİ (Right-click, zoom ekle)
  434.             def image_filter(i):
  435.                 return i.is_displayed() and i.size['width'] > 0 and i.size['height'] > 0
  436.  
  437.             images = safe_collect_elements(driver, By.TAG_NAME, "img", image_filter)
  438.             if images and random.random() < 0.35:
  439.                 img = random.choice(images)
  440.                 actions = ActionChains(driver)
  441.                 actions.move_to_element(img).pause(random.uniform(1.2, 3.5))
  442.                 if random.random() < 0.4:
  443.                     actions.context_click().perform()  # Right-click
  444.                 if random.random() < 0.3:
  445.                     driver.execute_script("arguments[0].style.zoom = '150%';", img)  # Zoom in
  446.                     time.sleep(2)
  447.                     driver.execute_script("arguments[0].style.zoom = '100%';", img)  # Zoom out
  448.                 actions.perform()
  449.  
  450.             def button_filter(b):
  451.                 return b.is_displayed() and "submit" not in b.get_attribute("type").lower() and b.size['width'] > 0 and b.size['height'] > 0
  452.  
  453.             buttons = safe_collect_elements(driver, By.CSS_SELECTOR, "button, input[type='button'], input[type='submit']", button_filter)
  454.             if buttons and random.random() < 0.25:
  455.                 btn = random.choice(buttons)
  456.                 def button_action():
  457.                     ActionChains(driver).move_to_element(btn).click().perform()
  458.                 perform_action_with_retry(button_action)
  459.                 time.sleep(random.uniform(4, 8))
  460.  
  461.             # 8. SAYFA İÇİ ARAMA (Daha sık)
  462.             if random.random() < 0.15:
  463.                 # Ctrl+F simülasyonu
  464.                 ActionChains(driver).key_down(Keys.CONTROL).send_keys('f').key_up(Keys.CONTROL).perform()
  465.                 time.sleep(1)
  466.                 search_box = driver.switch_to.active_element
  467.                 search_box.send_keys(random.choice(["anahtar", "kelime", "arama"]))  # Rastgele kelime
  468.                 time.sleep(random.uniform(3, 6))
  469.                 search_box.send_keys(Keys.ESCAPE)  # Kapat
  470.  
  471.             # 9. MOBILE SWIPE (Yeni, mobil trafik için mobil dokunuş simülasyonu)
  472.             if random.random() < 0.5:
  473.                 logging.info(f"{Fore.CYAN}Mobil swipe simüle ediliyor...{Fore.RESET}")
  474.                 actions = ActionChains(driver)
  475.                 # Rastgele swipe yukarı/aşağı
  476.                 swipe_direction = random.choice(["up", "down"])
  477.                 offset = random.randint(200, 600) if swipe_direction == "up" else -random.randint(200, 600)
  478.                 actions.click_and_hold().pause(random.uniform(0.2, 0.5)).move_by_offset(0, offset).pause(random.uniform(0.3, 0.7)).release().perform()
  479.                 time.sleep(random.uniform(1.5, 4.0))
  480.  
  481.             # 10. MOUSE HAREKETLERİ (Rastgele gezinme, bounds güvenli)
  482.             if random.random() < 0.4:
  483.                 logging.info(f"{Fore.CYAN}Rastgele mouse hareketi simüle ediliyor...{Fore.RESET}")
  484.                 body = driver.find_element(By.TAG_NAME, "body")
  485.                 viewport = driver.execute_script("return [window.innerWidth, window.innerHeight];")
  486.                 width, height = viewport[0], viewport[1]
  487.                 actions = ActionChains(driver)
  488.                 for _ in range(random.randint(3, 7)):
  489.                     offset_x = random.randint(-width // 2, width // 2)  # Göreli offset sınırlı
  490.                     offset_y = random.randint(-height // 2, height // 2)
  491.                     actions.move_to_element_with_offset(body, offset_x, offset_y).pause(random.uniform(0.5, 1.5)).perform()
  492.  
  493.             # 11. TEXT SEÇİMİ (Rastgele metin seçimi)
  494.             if random.random() < 0.25:
  495.                 paragraphs = safe_collect_elements(driver, By.TAG_NAME, "p")
  496.                 if paragraphs:
  497.                     p = random.choice(paragraphs)
  498.                     actions = ActionChains(driver)
  499.                     actions.move_to_element(p).click_and_hold().move_by_offset(random.randint(50, 150), 0).release().perform()
  500.                     time.sleep(random.uniform(2, 5))
  501.  
  502.             # 12. PINCH ZOOM (Mobil zoom simülasyonu)
  503.             if random.random() < 0.2:
  504.                 logging.info(f"{Fore.CYAN}Pinch zoom simüle ediliyor...{Fore.RESET}")
  505.                 driver.execute_script("document.body.style.zoom = '{}%';".format(random.randint(80, 120)))
  506.                 time.sleep(random.uniform(3, 6))
  507.                 driver.execute_script("document.body.style.zoom = '100%';")
  508.  
  509.             # 13. ÇİFT TIKLAMA (Rastgele elemente)
  510.             if random.random() < 0.15:
  511.                 elements = safe_collect_elements(driver, By.CSS_SELECTOR, "p, div, span")
  512.                 if elements:
  513.                     elem = random.choice(elements)
  514.                     ActionChains(driver).double_click(elem).perform()
  515.                     time.sleep(random.uniform(1, 3))
  516.  
  517.             # 14. FARE TEKERLEĞİ SCROLL (Wheel simülasyonu)
  518.             if random.random() < 0.3:
  519.                 driver.execute_script("window.scrollBy(0, {});".format(random.randint(-300, 300)))
  520.                 time.sleep(random.uniform(0.5, 2))
  521.  
  522.             # 15. RASTGELE KLAVYE GİRİŞİ (Yeni, harf harf doğal)
  523.             if random.random() < 0.1:
  524.                 logging.info(f"{Fore.CYAN}Rastgele klavye girişi simüle ediliyor...{Fore.RESET}")
  525.                 actions = ActionChains(driver)
  526.                 keys = random.choice([Keys.ARROW_DOWN, Keys.ARROW_UP, Keys.PAGE_DOWN, Keys.PAGE_UP])
  527.                 for _ in range(random.randint(1, 3)):
  528.                     actions.send_keys(keys)
  529.                     time.sleep(random.uniform(0.1, 0.3))
  530.                 actions.perform()
  531.                 time.sleep(random.uniform(1, 3))
  532.  
  533.             # 16. RASTGELE BEKLEME (Daha uzun pasiflik simüle, varyasyonlu)
  534.             time.sleep(random.uniform(15, 30) + random.uniform(-5, 5))
  535.  
  536.         except InvalidSessionIdException as e:
  537.             logging.error(f"Invalid session id hatası: {e} → Driver yenileniyor")
  538.             try: driver.quit()
  539.             except: pass
  540.             return  # Loop kır ve oturumu bitir, run_session retry yapacak
  541.         except Exception as e:
  542.             logging.error(f"Loop hatası: {e}")
  543.             time.sleep(2)  # Kısa gecikme ekle spam önlemek için
  544.             continue
  545.  
  546.     total_time = int(time.time() - start_time)
  547.     logging.info(f"{Fore.GREEN}OTURUM BİTTİ → {len(visited_urls)} sayfa, {total_time}s{Fore.RESET}")
  548.  
  549. # ====================== ANA BOT ======================
  550. def run_session():
  551.     for attempt in range(10):  # Retry sayısı arttırıldı
  552.         proxy_url, proxy = get_next_proxy()
  553.         driver = create_stealth_driver(proxy_url)
  554.         if not driver:
  555.             time.sleep(45)
  556.             continue
  557.  
  558.         selected_domain = random.choice(domains)  # Rastgele domain seç
  559.         start_url = f"https://{selected_domain}"
  560.  
  561.         try:
  562.             logging.info(f"{Fore.MAGENTA}Deneme {attempt+1}/10 | Domain: {selected_domain}{Fore.RESET}")
  563.             driver.get(start_url)
  564.             time.sleep(random.uniform(20, 30))
  565.  
  566.             if handle_captcha_and_rotate(driver, proxy):
  567.                 continue
  568.  
  569.             # ULTRA İNSAN DAVRANIŞI BAŞLAT
  570.             ultra_human_loop(driver, selected_domain)
  571.  
  572.         except InvalidSessionIdException as e:
  573.             logging.error(f"Session hatası: {e} → Retry yapılıyor")
  574.             try: driver.quit()
  575.             except: pass
  576.             time.sleep(2 ** attempt)  # Exponential backoff
  577.             continue
  578.         except WebDriverException as e:
  579.             logging.error(f"WebDriver hatası: {e} → Driver yenileniyor")
  580.             try: driver.quit()
  581.             except: pass
  582.             time.sleep(2 ** attempt)  # Exponential backoff
  583.             continue
  584.         except Exception as e:
  585.             logging.error(f"Deneme {attempt+1}/10 hatası: {e}")
  586.             try: driver.quit()
  587.             except: pass
  588.             time.sleep(20)
  589.             continue
  590.  
  591.         try: driver.quit()
  592.         except: pass
  593.         return
  594.  
  595.     logging.error(f"{Fore.RED}10 deneme başarısız → 90s bekleme{Fore.RESET}")
  596.     time.sleep(90)
  597.  
  598. # ====================== THREAD ======================
  599. def worker():
  600.     while True:
  601.         try:
  602.             run_session()
  603.             time.sleep(random.randint(min_wait_success, max_wait_success))
  604.         except:
  605.             time.sleep(90)
  606.  
  607. # ====================== BAŞLAT ======================
  608. if __name__ == "__main__":
  609.     banner()
  610.  
  611.     if not domains:
  612.         logging.critical("Domain yok!")
  613.         exit(1)
  614.  
  615.     for i in range(config.get("threads", 1)):
  616.         t = threading.Thread(target=worker, daemon=True)
  617.         t.start()
  618.         time.sleep(4)
  619.  
  620.     print(f"{Fore.CYAN}MEGA BOT v20.9 ÇALIŞIYOR | 5-15 DK | 16+ DAVRANIŞ | ÇOKLU DOMAIN | Log: mega_bot.log{Fore.RESET}")
  621.     try:
  622.         while True: time.sleep(1)
  623.     except KeyboardInterrupt:
  624.         print(f"\n{Fore.RED}BOT DURDURULDU.{Fore.RESET}")
Advertisement
Add Comment
Please, Sign In to add comment