python3使用多代理访问网站

#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Licence:     <your licence>
#-------------------------------------------------------------------------------
import io, sys, time, re, os, random
import winreg
import win32gui, win32con, win32api
import PAM30

proxy_list = [
{'proxy':"41.77.171.58:80"},
{'proxy':"41.73.2.36:8080"},
{'proxy':"41.77.172.229:80"},
{'proxy':"41.197.132.186:80"},
{'proxy':"41.215.247.146:80"},
{'proxy':"41.73.226.99:80"},
{'proxy':"61.177.248.202:1080"},
{'proxy':"41.77.173.79:80"},
{'proxy':"58.51.83.149:3128"},
{'proxy':"36.68.157.180:8080"},
{'proxy':"41.190.16.17:8080"},
{'proxy':"41.186.3.170:80"},
{'proxy':"14.140.0.178:3128"},
{'proxy':"41.197.132.186:8000"},
{'proxy':"41.78.103.42:8080"},
{'proxy':"41.73.2.35:8080"},
{'proxy':"41.75.201.146:3128"},
{'proxy':"41.79.65.109:80"},
{'proxy':"41.222.13.86:3128"},
{'proxy':"31.7.56.72:8080"},
{'proxy':"27.124.88.231:8080"},
{'proxy':"41.189.36.26:3128"},
{'proxy':"41.89.211.5:8080"},
{'proxy':"46.4.7.198:3128"},
{'proxy':"41.77.175.21:80"},
{'proxy':"41.78.239.1:8080"},
{'proxy':"41.75.201.146:8080"},
{'proxy':"14.140.0.178:80"},
{'proxy':"41.75.201.146:80"},
{'proxy':"46.4.248.80:3128"},
{'proxy':"41.221.156.50:3128"},
{'proxy':"41.191.53.1:8000"},
{'proxy':"41.205.110.66:8080"},
{'proxy':"58.22.151.6:80"},
{'proxy':"41.78.239.194:8080"},
{'proxy':"41.76.101.193:8080"},
{'proxy':"41.220.30.4:3128"},
{'proxy':"41.197.133.43:80"},
{'proxy':"41.196.22.244:3128"},
{'proxy':"41.196.22.244:8080"},
{'proxy':"31.3.227.85:3128"},
{'proxy':"41.75.204.71:8080"},
{'proxy':"27.111.35.3:8080"},
{'proxy':"31.7.56.72:80"}
]

def enableProxyIPPort(IP, Port):
    proxy = IP + ":" + str(Port)
    enableProxy(proxy)

def enableProxy(proxy):
    xpath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"
    try:
        key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, xpath, 0, winreg.KEY_WRITE)
        winreg.SetValueEx(key, "ProxyEnable", 0, winreg.REG_DWORD, 1)
        winreg.SetValueEx(key, "ProxyServer", 0, winreg.REG_SZ, proxy)
    except Exception as e:
        print("ERROR: " + str(e.args))
    finally:
        None

def main():
    weburl ="http://blog.doucube.com"
    #weburl ="http://ip.cn"
    try:

        for index in range(len(proxy_list)):
            cur_proxy = proxy_list[index]['proxy']
            print(cur_proxy)
            enableProxy(cur_proxy)

            ie = PAM30.PAMIE()
            ie.navigate(weburl)
            time.sleep(random.randint(10, 15))
            ie.quit()
            time.sleep(random.randint(1, 3))

    except Exception as e:
        print("ERROR: " + str(e.args))
    finally:
        pass


if __name__ == '__main__':
    main()

 

posted @ 2012-06-15 19:18  方倍工作室  阅读(3565)  评论(4编辑  收藏  举报