import requests from bs4 import BeautifulSoup def scrape_proxies(url): # Send a GET request to the URL print("Sending GET request to", url) response = requests.get(url) # Check if the request was successful if response.status_code == 200: print("Request successful") # Parse the HTML content soup = BeautifulSoup(response.content, 'html.parser') # Find all tables containing proxy information tables = soup.find_all('table', {'class': ['table-responsive fpl-list', 'table table-striped table-bordered']}) if tables: print("Found", len(tables), "tables with proxy information") # Extract proxy information from each table proxies = [] for table in tables: rows = table.find_all('tr') for row in rows[1:]: # Skip the header row cols = row.find_all('td') if len(cols) >= 7: ip = cols[0].text port = cols[1].text proxies.append(f"{ip}:{port}") print("Scraped", len(proxies), "proxies") return proxies else: print("Tables with proxy information not found") return [] else: print("Failed to retrieve page:", response.status_code) return [] def test_proxy(proxy): try: # Define the URL to test the proxy test_url = "https://httpbin.org/ip" # Make a request using the proxy response = requests.get(test_url, proxies={"http": proxy, "https": proxy}, timeout=5) # Check if the request was successful if response.status_code == 200: print("Proxy:", proxy, "is working") print("Your IP:", response.json()["origin"]) return True else: print("Failed to connect to", proxy) return False except Exception as e: print("Error occurred while testing proxy:", str(e)) return False if __name__ == "__main__": url = "https://www.sslproxies.org/" # Scrape proxies proxies = scrape_proxies(url) # Test proxies if proxies: print("\nTesting proxies:") working_proxies = [] for proxy in proxies: if test_proxy(proxy): working_proxies.append(proxy) # Print final list of working proxies print("\nFinal list of working proxies:") for proxy in working_proxies: print(proxy)