Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from urllib.request import Request, urlopen
- from bs4 import BeautifulSoup
- from fake_useragent import UserAgent
- import random
- from selenium import webdriver
- ua = UserAgent() # From here we generate a random user agent
- proxies = [] # Will contain proxies [ip, port]
- # Main function
- def main():
- # Retrieve latest proxies
- proxies_req = Request('https://www.sslproxies.org/')
- proxies_req.add_header('User-Agent', ua.random)
- proxies_doc = urlopen(proxies_req).read().decode('utf8')
- soup = BeautifulSoup(proxies_doc, 'html.parser')
- proxies_table = soup.find(id='proxylisttable')
- # Save proxies in the array
- for row in proxies_table.tbody.find_all('tr'):
- proxies.append({
- 'ip': row.find_all('td')[0].string,
- 'port': row.find_all('td')[1].string
- })
- # Choose a random proxy
- proxy_index = random_proxy()
- proxy = proxies[proxy_index]
- print("Proxy list added!");
- #
- # headers = { 'Accept':'*/*',
- # 'Accept-Encoding':'gzip, deflate, sdch',
- # 'Accept-Language':'en-US,en;q=0.8',
- # 'Cache-Control':'max-age=0',
- # 'User-Agent': ua.random
- # }
- #
- # for key, value in enumerate(headers):
- # capability_key = 'phantomjs.page.customHeaders.{}'.format(key)
- # webdriver.DesiredCapabilities.PHANTOMJS[capability_key] = value
- #
- # webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.settings.resourceTimeout'] = "3000";
- for n in range(1, 20):
- try:
- PROXY = proxy['ip'] + ':' + proxy['port'] # IP:PORT or HOST:PORT
- chrome_options = webdriver.ChromeOptions()
- chrome_options.add_argument('--proxy-server=http://%s' % PROXY)
- # options.add_argument('headless')
- driver = webdriver.Chrome(options=chrome_options)
- # driver.get("http://whatismyipaddress.com")
- #
- # driver = webdriver.PhantomJS(desired_capabilities={'phantomjs.page.settings.resourceTimeout': '2000'}, service_args=service_args)
- driver.get("https://woobox.com/2swm4v/gallery/yKudhXTWaPs")
- print("Get url");
- p_element = driver.find_element_by_id(id_='gallery-media-container')
- btn = p_element.find_element_by_link_text("Vote")
- btn.click()
- print("~~~~~~~~~~~~~~~ Voted !!!!! ~~~~~~~~~~~~~~~")
- proxy_index = random_proxy()
- proxy = proxies[proxy_index]
- driver.close()
- except: # If error, delete this proxy and find another one
- del proxies[proxy_index]
- print('Proxy ' + proxy['ip'] + ':' + proxy['port'] + ' deleted.')
- proxy_index = random_proxy()
- proxy = proxies[proxy_index]
- # Retrieve a random index proxy (we need the index to delete it if not working)
- def random_proxy():
- return random.randint(0, len(proxies) - 1)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement