From ThanhTuan, 9 Months ago, written in Python.
This paste is a reply to UserAgent from ThanhTuan - view diff
Embed
  1. from selenium import webdriver
  2. from selenium.webdriver.common.proxy import *
  3. from selenium.common.exceptions import TimeoutException
  4. from selenium.webdriver.support.ui import WebDriverWait
  5. from pyvirtualdisplay import Display
  6. from multiprocessing.dummy import Pool as ThreadPool
  7. import time
  8. import random
  9. import urllib2
  10. import socks
  11. from sockshandler import SocksiPyHandler
  12. import socket
  13. import os, shutil
  14.  
  15. input_file = 'proxies.txt'
  16. file_userAgent = 'userAgent.txt'
  17. hosts = [host.strip() for host in open(input_file).readlines()]
  18. userAgent = [agent.strip() for agent in open(file_userAgent).readlines()]
  19. 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/']
  20. def ChangeProxy(ProxyHost, ProxyPort):
  21.     "Define Firefox Profile with you ProxyHost and ProxyPort"
  22.     profile = webdriver.FirefoxProfile()
  23.     profile.set_preference("network.proxy.type", 1)
  24.     #profile.set_preference("network.proxy.http", ProxyHost)
  25.     #profile.set_preference("network.proxy.http_port", int(ProxyPort))
  26.     profile.set_preference("network.proxy.socks", ProxyHost)
  27.     profile.set_preference("network.proxy.socks_port", int(ProxyPort))
  28.     profile.set_preference("network.proxy.socks_version", 5)
  29.     profile.set_preference("browser.cache.disk.enable", False)
  30.     profile.set_preference("browser.cache.memory.enable", False)
  31.     profile.set_preference("browser.cache.offline.enable", False)
  32.     profile.set_preference("network.http.use-cache", False)
  33.     profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',False)
  34.     profile.set_preference("media.peerconnection.enabled", False)
  35.     profile.set_preference("general.useragent.override", random.choice(userAgent))
  36.     profile.update_preferences()
  37.     return webdriver.Firefox(executable_path="/usr/bin/geckodriver",firefox_profile=profile)
  38. i = 0
  39. def do_bot(item):
  40.     item = item.strip()
  41.     proxy = item.split(':')
  42.     try:
  43.         opener = urllib2.build_opener(
  44.              SocksiPyHandler(socks.PROXY_TYPE_SOCKS5, proxy[0], int(proxy[1]))
  45.         )
  46.         #proxy_support = urllib2.ProxyHandler({"http":item})
  47.         #opener = urllib2.build_opener(proxy_support)
  48.         #urllib2.install_opener(opener)
  49.         #req = urllib2.urlopen("https://coccoc.com/",timeout=6)
  50.         req = opener.open("http://bing.com", timeout=6)
  51.         content = req.read()
  52.         try:
  53.             driver = ChangeProxy(proxy[0],proxy[1])
  54.             # Resize the window to the screen width/height
  55.             print "Running Proxy -> %s" % (item) +"\n"
  56.             # http://phim18hd.top
  57.             driver.get(random.choice(sitelinks))
  58.             links = driver.find_elements_by_partial_link_text('')
  59.             l = links[random.randint(0, len(links)-1)]
  60.             l.click()
  61.             time.sleep(1)
  62.             l.click()
  63.             time.sleep(1)
  64.             l.click()
  65.             time.sleep(1)
  66.             l.click()
  67.             time.sleep(6)
  68.             driver.delete_all_cookies()
  69.             driver.quit()
  70.         except:
  71.             driver.quit()
  72.     except urllib2.HTTPError, e:
  73.         print "Bad Proxy -> %s" % (item)+"\n"
  74.     except Exception, detail:
  75.         print "ERROR Connect proxy %s" % (detail)+"\n"
  76. pool = ThreadPool(2)
  77. display = Display(visible=0, size=(800, 600))
  78. display.start()
  79. results = pool.map(do_bot,hosts)
  80. pool.close()
  81. pool.join()
  82. display.stop()
  83. print "%s Proxy is Working" % (i)
  84.