from selenium import webdriver
from selenium.webdriver.common.proxy import *
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from pyvirtualdisplay import Display
from multiprocessing.dummy import Pool as ThreadPool
import time
import random
import urllib2
import socks
from sockshandler import SocksiPyHandler
import socket
import os, shutil
input_file = 'proxies.txt'
file_userAgent = 'userAgent.txt'
hosts = [host.strip() for host in open(input_file).readlines()]
userAgent = [agent.strip() for agent in open(file_userAgent).readlines()]
sitelinks = ['https://www.bikipcuocsong.com','http://phim18hd.top','https://www.bikipcuocsong.com/bitcoin/','http://phim18hd.top/video/phim-18-han-quoc-nhiep-anh-gia-va-nguoi-mau-chich-xa-giao/','http://phim18hd.top/categories/phim-18-han-quoc/','https://www.bikipcuocsong.com/anh-nguoi-dep/anh-bikini-ngoc-trinh/']
def ChangeProxy(ProxyHost, ProxyPort):
"Define Firefox Profile with you ProxyHost and ProxyPort"
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
#profile.set_preference("network.proxy.http", ProxyHost)
#profile.set_preference("network.proxy.http_port", int(ProxyPort))
profile.set_preference("network.proxy.socks", ProxyHost)
profile.set_preference("network.proxy.socks_port", int(ProxyPort))
profile.set_preference("network.proxy.socks_version", 5)
profile.set_preference("browser.cache.disk.enable", False)
profile.set_preference("browser.cache.memory.enable", False)
profile.set_preference("browser.cache.offline.enable", False)
profile.set_preference("network.http.use-cache", False)
profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',False)
profile.set_preference("media.peerconnection.enabled", False)
profile.set_preference("general.useragent.override", random.choice(userAgent))
profile.update_preferences()
return webdriver.Firefox(executable_path="/usr/bin/geckodriver",firefox_profile=profile)
i = 0
def do_bot(item):
item = item.strip()
proxy = item.split(':')
try:
opener = urllib2.build_opener(
SocksiPyHandler(socks.PROXY_TYPE_SOCKS5, proxy[0], int(proxy[1]))
)
#proxy_support = urllib2.ProxyHandler({"http":item})
#opener = urllib2.build_opener(proxy_support)
#urllib2.install_opener(opener)
#req = urllib2.urlopen("https://coccoc.com/",timeout=6)
req = opener.open("http://bing.com", timeout=6)
content = req.read()
try:
driver = ChangeProxy(proxy[0],proxy[1])
# Resize the window to the screen width/height
print "Running Proxy -> %s" % (item) +"\n"
# http://phim18hd.top
driver.get(random.choice(sitelinks))
links = driver.find_elements_by_partial_link_text('')
l = links[random.randint(0, len(links)-1)]
l.click()
time.sleep(1)
l.click()
time.sleep(1)
l.click()
time.sleep(1)
l.click()
time.sleep(6)
driver.delete_all_cookies()
driver.quit()
except:
driver.quit()
except urllib2.HTTPError, e:
print "Bad Proxy -> %s" % (item)+"\n"
except Exception, detail:
print "ERROR Connect proxy %s" % (detail)+"\n"
pool = ThreadPool(2)
display = Display(visible=0, size=(800, 600))
display.start()
results = pool.map(do_bot,hosts)
pool.close()
pool.join()
display.stop()
print "%s Proxy is Working" % (i)