Advertisement
Guest User

Untitled

a guest
Nov 29th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. import requests
  2. import time
  3.  
  4. proxy_list = []
  5. # открываем файл с прокси
  6. with open('proxy.txt', 'r', encoding='utf-8') as f:
  7.     # берем первые 100
  8.     for s in range(100):
  9.         proxy_list.append(next(f))
  10.  
  11. # выводим в консоль список
  12. print(proxy_list)
  13.  
  14. # словарь для текущего прокси
  15. proxies = {'https': '10.10.10.10:8080'}
  16.  
  17. # цикл - пока в списке не останется прокси
  18. while len(proxy_list) > 0:
  19.  
  20.     # убираем прокси из списка
  21.     proxies = {'https': proxy_list.pop()}
  22.     # пробуем через него подключиться
  23.     try:
  24.         # проверяем прокси, отправляем через него запрос на google.com
  25.         response = requests.get('https://google.com', proxies=proxies)        
  26.        
  27.         # выводим в консоль прокси и код ответа сервера
  28.         print(proxies, response.status_code)
  29.  
  30.     # ошибки выводим в консоль
  31.     except Exception as e:
  32.         print(e)
  33.  
  34.     # ждем секунду
  35.     time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement