Advertisement
crazybaofulusha

Untitled

Mar 25th, 2019
13,548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. #!"C:\Program Files\Python\python.exe"
  2. # -*- coding:utf-8 -*-
  3.  
  4. import urllib.request
  5.  
  6.  
  7. def auth_proxy(request, opener, urlerror_code):
  8.     try:
  9.         response = opener.open(request, timeout=10)
  10.     except urllib.request.HTTPError as err:
  11.         return err.code
  12.     except urllib.request.URLError as err:
  13.         return urlerror_code
  14.     else:
  15.         return response.getcode()
  16.  
  17.  
  18. if __name__ == "__main__":
  19.  
  20.     urlerror_code = 600
  21.  
  22.     proxy_list = ['http://121.54.175.94:27787',
  23.                   'http://122.116.238.22:30032',
  24.                   'http://132.148.13.46:53424',
  25.                   'http://132.148.13.46:35807',
  26.                   'http://132.148.3.216:31785',
  27.                   'http://166.62.84.121:52468',
  28.                   'http://166.62.84.121:44147',
  29.                   'http://166.62.83.129:44147',
  30.                   'http://166.62.83.129:30834',
  31.                   'http://166.62.84.121:18984',
  32.                   'http://166.62.84.121:12269',
  33.                   'http://166.62.83.129:12269',
  34.                   'http://166.62.83.129:26232']
  35.  
  36.     headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36"}
  37.     request = urllib.request.Request("http://www.google.com", headers=headers, proxies=proxy_list)
  38.  
  39.     good_list = []
  40.     for proxy in proxy_list:
  41.         proxy_handler = urllib.request.ProxyHandler(proxy)
  42.         opener = urllib.request.build_opener(proxy_handler)
  43.  
  44.         num = auth_proxy(request, opener, urlerror_code)
  45.  
  46.         if num == 200:
  47.             good_list.append(proxy)
  48.     print(good_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement