Fastest Proxy Iteration in Python

后端 未结 1 1396
北荒
北荒 2021-01-28 00:31

Let\'s say I have a list that contains 10,000+ proxies

proxy_list = [\'ip:port\',\'ip:port\',.....10,000+ items]

How do I iterate it to get the

相关标签:
1条回答
  • 2021-01-28 00:32

    You could use threading, this would allow the program to check multiple proxies at once.

    import requests
    import threading
    import concurrent.futures
    
    appendLock = threading.Lock() """This is to keep multiple threads from appending 
    to the list at the same time"""
    
    workers = 10 """This is the number of threads that will iterate through your proxy list.
    In my experience, increasing this number higher than 30 causes problems."""
    
    proxy_list = ['ip:port','ip:port',.....10,000+ items]
    
    result = []
    
    def proxyCheck(proxy):
        try:
            requests.get('http://www.httpbin.org/ip',proxies = {'https' : I, 'http' : I } ,timeout = 5)
            with appendLock:
                result.append(I)
        except:
            pass
    
    with concurrent.futures.ThreadPoolExecutor(max_workers=workers) as executor:
        for proxy in proxy_list:
            executor.submit(proxyCheck(proxy))
    
    0 讨论(0)
提交回复
热议问题