Ücretsiz Cookie Creator (Forum Ruhunu Diriltiyorum Konu 1)
HER ŞEY PARA DEĞİL!!!
Arkadaşlar elimde bir proxy destekli olabildiğince özgün cookie oluşturmaya yarayan bir kod var. Bu işin uzmanları lütfen incelesin baksın ve ona göre söylesin. Bu kod bir işe yarar mı yaramaz mı diye. Ayrıca bu kodun ortaya çıkardığı cookieler nerelerde kullanılır. Onu da söylerlerse iyi olur. Örnek çıktıyı ben bırakmıyorum test edip deneyenler bizi aydınlatsın. Ayrıca kodu kullanmak için taget iste ve proxy kısımlarını güncellemek lazımdır ona göre.
import json
import random
import time
import uuid
from datetime import datetime
import requests
from playwright.sync_api import sync_playwright, BrowserContext, Page
import logging
import argparse
import os
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
# Configuration
TARGET_WEBSITE = "https://google.com" # Replace with your target website
IP_DETECTION_API = "https://api.ipify.org?format=json"
OUTPUT_FILE = "visitors.json"
# Browser fingerprint options
USER_AGENTS = [
# Chrome on Windows
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
# Chrome on macOS
"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",
# Chrome on Linux
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
# Firefox on Windows
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0",
# Firefox on macOS
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:121.0) Gecko/20100101 Firefox/121.0",
# Safari on macOS
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Safari/605.1.15"
]
# Common viewport sizes
VIEWPORTS = [
{"width": 1920, "height": 1080}, # Full HD
{"width": 1366, "height": 768}, # Common laptop
{"width": 1440, "height": 900}, # Macbook Pro
{"width": 1536, "height": 864}, # Surface Laptop
{"width": 1280, "height": 720} # HD
]
# Language settings
LANGUAGES = [
"en-US,en;q=0.9",
"en-GB,en;q=0.9",
"es-ES,es;q=0.9",
"fr-FR,fr;q=0.9",
"de-DE,de;q=0.9",
"ja-JP,ja;q=0.9",
"zh-CN,zh;q=0.9"
]
# Timezones
TIMEZONES = [
"America/New_York",
"Europe/London",
"Europe/Paris",
"Asia/Tokyo",
"Australia/Sydney",
"America/Los_Angeles"
]
def validate_proxy(proxy):
"""
Validate proxy format.
Args:
proxy (str): Proxy string to validate
Returns:
bool: True if valid, False otherwise
"""
if not proxy:
return False
# Check if proxy starts with http:// or https:// or socks5://
if not (proxy.startswith("http://") or proxy.startswith("https://") or proxy.startswith("socks5://")):
return False
# Basic format check
if "@" in proxy:
# Format: protocol://user:password@host:port
parts = proxy.split("@")
if len(parts) != 2:
return False
# Check protocol part
protocol_part = parts[0]
if not (protocol_part.startswith("http://") or protocol_part.startswith("https://") or protocol_part.startswith("socks5://")):
return False
# Check host:port part
host_port = parts[1]
if ":" not in host_port:
return False
host, port = host_port.split(":")
if not host or not port.isdigit():
return False
else:
# Format: protocol://host:port
if ":" not in proxy:
return False
parts = proxy.split("://")
if len(parts) != 2:
return False
host_port = parts[1]
if ":" not in host_port:
return False
host, port = host_port.split(":")
if not host or not port.isdigit():
return False
return True
def setup_browser_with_proxy(proxy):
"""
Set up a browser with the specified proxy and randomized fingerprint.
Args:
proxy (str): Proxy in format "http://user:password@host:port"
Returns:
tuple: (playwright, browser, context) or (None, None, None) if failed
"""
playwright = None
browser = None
context = None
try:
if not validate_proxy(proxy):
logger.error(f"Invalid proxy format: {proxy}")
return None, None, None
playwright = sync_playwright().start()
# Parse proxy for Playwright
proxy_config = {}
if "@" in proxy:
# Format: http://user:pass@host:port
protocol, rest = proxy.split("://")
auth, host_port = rest.split("@")
username, password = auth.split(":")
proxy_config = {
"server": f"{protocol}://{host_port}",
"username": username,
"password": password
}
else:
proxy_config = {"server": proxy}
# Launch browser with proxy
browser = playwright.chromium.launch(
headless=True,
proxy=proxy_config
)
# Randomize fingerprint
user_agent = random.choice(USER_AGENTS)
viewport = random.choice(VIEWPORTS)
language = random.choice(LANGUAGES)
locale = language.split(",")[0]
timezone_id = random.choice(TIMEZONES)
# Create browser context with fingerprint
context = browser.new_context(
user_agent=user_agent,
viewport=viewport,
locale=locale,
timezone_id=timezone_id,
extra_http_headers={
"Accept-Language": language
}
)
logger.info(f"Browser set up with proxy {proxy.split('@')[-1] if '@' in proxy else proxy}")
return playwright, browser, context
except Exception as e:
logger.error(f"Error setting up browser with proxy: {e}")
# Clean up on error
if browser:
browser.close()
if playwright:
playwright.stop()
return None, None, None
def simulate_mouse_movements(page):
"""
Simulate realistic mouse movements on the page.
Args:
page (Page): Playwright page object
"""
try:
# Get viewport dimensions
viewport = page.viewport_size
# Number of mouse movements
movements = random.randint(3, 8)
for _ in range(movements):
# Random position within viewport
x = random.randint(0, viewport["width"])
y = random.randint(0, viewport["height"])
# Move mouse with random duration
duration = random.uniform(100, 500) # milliseconds
page.mouse.move(x, y, steps=int(duration/10))
# Random pause between movements
time.sleep(random.uniform(0.1, 0.5))
logger.debug("Simulated mouse movements")
except Exception as e:
logger.error(f"Error simulating mouse movements: {e}")
def simulate_scroll_behavior(page):
"""
Simulate realistic scrolling behavior on the page.
Args:
page (Page): Playwright page object
"""
try:
# Get page height
page_height = page.evaluate("document.body.scrollHeight")
viewport_height = page.viewport_size["height"]
# If page is scrollable
if page_height > viewport_height:
# Number of scroll actions
scrolls = random.randint(1, 3)
for _ in range(scrolls):
# Random scroll distance (but not beyond page bounds)
current_scroll = page.evaluate("window.pageYOffset")
max_scroll = page_height - viewport_height
# Random scroll direction and distance
if random.random() < 0.7: # 70% chance to scroll down
scroll_distance = random.randint(100, min(500, max_scroll - current_scroll))
else: # 30% chance to scroll up
scroll_distance = -random.randint(100, min(500, current_scroll))
# Scroll with animation
page.evaluate(f"window.scrollBy(0, {scroll_distance})")
time.sleep(random.uniform(1, 3))
logger.debug("Simulated scroll behavior")
except Exception as e:
logger.error(f"Error simulating scroll behavior: {e}")
def simulate_click_behavior(page):
"""
Simulate clicking on internal links with some probability.
Args:
page (Page): Playwright page object
"""
try:
# 50% chance to click a link
if random.random() < 0.5:
# Find all links
links = page.query_selector_all("a[href]")
if links:
# Filter for internal links (same domain)
internal_links = []
for link in links:
href = link.get_attribute("href")
if href and (not href.startswith("http") or (TARGET_WEBSITE in href)):
internal_links.append(link)
if internal_links:
# Click a random internal link
random_link = random.choice(internal_links)
# Scroll link into view if needed
random_link.scroll_into_view_if_needed()
time.sleep(random.uniform(0.5, 1.5))
# Click the link
random_link.click()
# Wait for page to load
time.sleep(random.uniform(2, 5))
# Go back to the original page
page.go_back()
time.sleep(random.uniform(1, 3))
logger.debug("Simulated click behavior")
except Exception as e:
logger.error(f"Error simulating click behavior: {e}")
def simulate_user_behavior(page):
"""
Simulate realistic user behavior on the page.
Args:
page (Page): Playwright page object
"""
try:
# Initial wait to simulate page reading
time.sleep(random.uniform(3, 8))
# Simulate mouse movements
simulate_mouse_movements(page)
# Simulate scrolling
simulate_scroll_behavior(page)
# Simulate clicking behavior
simulate_click_behavior(page)
# Final wait before leaving
time.sleep(random.uniform(1, 3))
logger.info("Simulated user behavior")
except Exception as e:
logger.error(f"Error simulating user behavior: {e}")
def get_public_ip(page):
"""
Get the public IP address used by the browser.
Args:
page (Page): Playwright page object
Returns:
str: Public IP address or None if failed
"""
try:
# Navigate to IP detection API
response = page.goto(IP_DETECTION_API)
content = response.text()
# Extract IP from JSON response
ip_data = json.loads(content)
ip = ip_data.get("ip")
logger.info(f"Detected IP: {ip}")
return ip
except Exception as e:
logger.error(f"Error detecting IP: {e}")
return None
def extract_cookies(context):
"""
Extract all cookies from the browser context.
Args:
context (BrowserContext): Playwright browser context
Returns:
list: List of cookie objects
"""
try:
cookies = context.cookies()
logger.info(f"Extracted {len(cookies)} cookies")
return cookies
except Exception as e:
logger.error(f"Error extracting cookies: {e}")
return []
def generate_visitor(proxy):
"""
Generate a single visitor using the specified proxy.
Args:
proxy (str): Proxy in format "http://user:password@host:port"
Returns:
dict: Visitor data or empty dict if failed
"""
playwright = None
browser = None
visitor_data = {}
try:
# Set up browser with proxy
playwright, browser, context = setup_browser_with_proxy(proxy)
if not browser or not context:
return {}
# Create a new page
page = context.new_page()
# Get public IP
ip = get_public_ip(page)
# Visit the target website
response = page.goto(TARGET_WEBSITE)
# Check if page loaded successfully
if not response or response.status >= 400:
logger.error(f"Failed to load {TARGET_WEBSITE}, status: {response.status if response else 'None'}")
return {}
# Simulate user behavior
simulate_user_behavior(page)
# Extract cookies
cookies = extract_cookies(context)
# Get user agent from the page
user_agent = page.evaluate("navigator.userAgent")
# Create visitor data
visitor_data = {
"proxy": proxy.split("@")[-1] if "@" in proxy else proxy, # Hide credentials in output
"ip": ip,
"user_agent": user_agent,
"visit_time": datetime.now().isoformat(),
"cookies": cookies
}
logger.info(f"Generated visitor with IP {ip}")
except Exception as e:
logger.error(f"Error generating visitor: {e}")
finally:
# Clean up
if browser:
browser.close()
if playwright:
playwright.stop()
return visitor_data
def generate_visitors(count, proxies):
"""
Generate multiple visitors using the provided proxies.
Args:
count (int): Number of visitors to generate
proxies (list): List of proxy strings
Returns:
list: List of visitor data dictionaries
"""
if not proxies:
logger.error("No proxies provided")
return []
# Validate all proxies
valid_proxies = []
for proxy in proxies:
if validate_proxy(proxy):
valid_proxies.append(proxy)
else:
logger.warning(f"Invalid proxy format, skipping: {proxy}")
if not valid_proxies:
logger.error("No valid proxies provided")
return []
visitors = []
for i in range(count):
# Rotate proxies
proxy = valid_proxies[i % len(valid_proxies)]
logger.info(f"Generating visitor {i+1}/{count} with proxy {proxy.split('@')[-1] if '@' in proxy else proxy}")
# Generate visitor
visitor = generate_visitor(proxy)
if visitor:
visitors.append(visitor)
else:
logger.warning(f"Failed to generate visitor with proxy {proxy.split('@')[-1] if '@' in proxy else proxy}")
# Random delay between visitors
time.sleep(random.uniform(1, 3))
logger.info(f"Generated {len(visitors)} visitors out of {count} requested")
return visitors
def save_visitors(visitors, filename=OUTPUT_FILE):
"""
Save visitors data to a JSON file.
Args:
visitors (list): List of visitor data dictionaries
filename (str): Output filename
"""
try:
with open(filename, "w") as f:
json.dump(visitors, f, indent=2)
logger.info(f"Saved {len(visitors)} visitors to {filename}")
except Exception as e:
logger.error(f"Error saving visitors: {e}")
def load_proxies_from_file(filename):
"""
Load proxies from a file, one per line.
Args:
filename (str): Path to the proxy file
Returns:
list: List of proxy strings
"""
proxies = []
try:
with open(filename, "r") as f:
for line in f:
line = line.strip()
if line and not line.startswith("#"): # Skip empty lines and comments
proxies.append(line)
logger.info(f"Loaded {len(proxies)} proxies from {filename}")
except Exception as e:
logger.error(f"Error loading proxies from file: {e}")
return proxies
def main():
"""
Main function to generate visitors and save to file.
"""
global TARGET_WEBSITE, OUTPUT_FILE
# Parse command line arguments
parser = argparse.ArgumentParser(description="Generate realistic website visitors using residential proxies and headless browser.")
parser.add_argument("--count", type=int, default=10, help="Number of visitors to generate (default: 10)")
parser.add_argument("--proxies", nargs="+", help="List of proxies in format 'http://user:password@host:port'")
parser.add_argument("--proxy-file", type=str, help="File containing proxies, one per line")
parser.add_argument("--output", type=str, default=OUTPUT_FILE, help=f"Output file (default: {OUTPUT_FILE})")
parser.add_argument("--website", type=str, default=TARGET_WEBSITE, help=f"Target website (default: {TARGET_WEBSITE})")
parser.add_argument("--min-visitors", type=int, default=10, help="Minimum number of valid visitors required (default: 10)")
args = parser.parse_args()
# Update global variables with command line arguments
TARGET_WEBSITE = args.website
OUTPUT_FILE = args.output
# Get proxies
proxies = []
if args.proxies:
proxies.extend(args.proxies)
if args.proxy_file:
if os.path.exists(args.proxy_file):
file_proxies = load_proxies_from_file(args.proxy_file)
proxies.extend(file_proxies)
else:
logger.error(f"Proxy file not found: {args.proxy_file}")
return
# If no proxies provided, use built-in proxies for target
if not proxies:
logger.warning("No proxies provided, using built-in proxies")
proxies = [
"http://kullanıcıadı:şifre@ip:port",
]
# Generate visitors
visitors = generate_visitors(args.count, proxies)
# Check if we have enough valid visitors
if len(visitors) < args.min_visitors:
logger.warning(f"Only generated {len(visitors)} valid visitors, which is less than the minimum required ({args.min_visitors})")
# Save visitors to file
save_visitors(visitors, args.output)
if __name__ == "__main__":
main()