Python and selenium

pip3 install selenium
      
        

      


pip3 install undetected-chromedriver
      
        

      


import undetected_chromedriver as uc
import time

# Initialize Chrome with undetected ChromeDriver
browser = uc.Chrome(headless=True, use_subprocess=True)

# Navigate to the target page
browser.get("https://example.com")

# Wait a few seconds to ensure the page loads fully
time.sleep(3)

# Save a screenshot to verify page loading
browser.save_screenshot("screenshot.png")
print("Screenshot taken and saved as 'screenshot.png'")

# Close the browser after the task
browser.quit()
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
      


from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

# List of DataImpulse proxies 
proxy_list = [ 
    "proxy1:port", 
    "proxy2:port", 
    "proxy3:port", 
    # Add more proxies from your DataImpulse pool 
]

def start_selenium_with_proxy(proxy):
    # Set up Chrome options
    chrome_options = Options()
    chrome_options.add_argument("--headless=new")

    # Add proxy to Chrome options
    chrome_options.add_argument(f'--proxy-server=http://{proxy}')

    # Initialize the Selenium browser with the proxy settings
    driver = webdriver.Chrome(options=chrome_options)
    return driver

# Example scraping function with using rotating proxies
def scrape_website():
    for proxy in proxy_list:
        driver = start_selenium_with_proxy(proxy)
        try:
            # Navigate to the target website
            driver.get("https://httpbin.io/ip")

            print(driver.find_element(By.TAG_NAME, "body").text)
            
        finally:
            driver.quit()

# Run the scraping function
scrape_website() 
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
      


import time
import random
import requests

# make a GET request to the given URL and print the status code
def make_request(url):
    response = requests.get(url)
    print(f"Request to {url} returned status code: {response.status_code}")

# list of URLs to request
urls = [
    "https://www.scrapingcourse.com/ecommerce/page/1/",
    "https://www.scrapingcourse.com/ecommerce/page/2/",
    "https://www.scrapingcourse.com/ecommerce/page/3/",
]

# range for random wait time (in seconds)
min_wait = 1
max_wait = 5

# iterate through each URL in the list
for url in urls:
    make_request(url)
    wait_time = random.uniform(min_wait, max_wait)
    print(f"Waiting for {wait_time:.2f} seconds before the next request...")
    time.sleep(wait_time)

print("All requests completed.") 
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
      


# pip3 install requests
import requests
import time

# TODO: Set your configuration
api_key = "YOUR_API_KEY"  # Your CapSolver API key
site_key = "XXX"  # The site key for the target CAPTCHA
site_url = ""  # URL of the page with the CAPTCHA

def capsolver():
    payload = {
        "clientKey": api_key,
        "task": {
            "type": 'ReCaptchaV2TaskProxyLess',
            "websiteKey": site_key,
            "websiteURL": site_url
        }
    }

    response = requests.post("https://api.capsolver.com/createTask", json=payload)
    result = response.json()
    task_id = result.get("taskId")

    if not task_id:
        print("Failed to create task:", response.text)
        return

    print(f"Task ID received: {task_id} / Fetching result...")

    while True:
        time.sleep(3)  # Delay between checks

        payload = {"clientKey": api_key, "taskId": task_id}
        response = requests.post("https://api.capsolver.com/getTaskResult", json=payload)
        result = response.json()
        status = result.get("status")

        if status == "ready":
            return result.get("solution", {}).get('gRecaptchaResponse')

        if status == "failed" or result.get("errorId"):
            print("Solution retrieval failed! Response:", response.text)
            return

token = capsolver()
print(token)
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
      

Share article: