Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import zipfile
- import time
- from selenium import webdriver
- from selenium.webdriver import DesiredCapabilities
- import threading
- import requests
- from selenium.webdriver.common.keys import Keys
- PROXY_HOST = 'x.botproxy.net' # rotating proxy
- PROXY_PORT = 8080
- PROXY_USER = 'pxu10288-0'
- PROXY_PASS = 'DczaZFwD4af*1BBG^is7'
- captcha_api_key = "ea5afa171b76afc5df1eb30d68e8cb69"
- def get_chromedriver(use_proxy=False, user_agent=None):
- path = os.path.dirname(os.path.abspath(__file__))
- chrome_options = webdriver.ChromeOptions()
- if use_proxy:
- pluginfile = 'proxy_auth_plugin.zip'
- with zipfile.ZipFile(pluginfile, 'w') as zp:
- zp.writestr("manifest.json", manifest_json)
- zp.writestr("background.js", background_js)
- chrome_options.add_extension(pluginfile)
- if user_agent:
- chrome_options.add_argument('--user-agent=%s' % user_agent)
- driver = webdriver.Chrome(
- os.path.join(path, 'chromedriver'),
- chrome_options=chrome_options)
- return driver
- def check_recaptcha(driver):
- if "recaptcha" in driver.page_source:
- recaptcha = driver.find_elements_by_xpath("//*[@data-sitekey]")
- for a in recaptcha:
- g_key = a.get_attribute("data-sitekey")
- print(g_key)
- page_url = driver.current_url
- url = "http://2captcha.com/in.php?key=" + captcha_api_key + "&method=userrecaptcha&googlekey=" + g_key + "&json=1&pageurl=" + page_url
- r1 = requests.get(url = url)
- print("Request Made")
- captcha_id = eval(r1.text)["request"]
- while True:
- answer = requests.get("http://2captcha.com/res.php?key="+captcha_api_key+"&action=get&json=1&id="+captcha_id)
- if eval(answer.text)["request"] == "CAPCHA_NOT_READY":
- print("Captcha Not Ready")
- time.sleep(2)
- continue
- else:
- print("Captcha Ready.Breaking")
- print(answer.text)
- break
- ans = eval(answer.text)
- js_exe = "document.getElementById('g-recaptcha-response').innerHTML = "+"'"+ans["request"]+"'"
- print(js_exe)
- driver.execute_script(js_exe)
- print("Script Executed")
- driver.find_element_by_name("submit").click()
- else:
- print("Recaptcha Didnt Appear")
- return driver
- def main(user_agent= None):
- # drivers.append(driver)
- key_words = ["SEO Toronto"]
- for word in key_words:
- temp_word = word.replace(" ", "+")
- driver = get_chromedriver(use_proxy=use_proxy, user_agent=user_agent)
- data = driver.get("https://www.google.ca/search?q="+temp_word)
- check_recaptcha(driver)
- elems = driver.find_elements_by_xpath("//a[@href]")
- found = 0
- for elem in elems:
- if elem.get_attribute("href") == "https://kanwarmanoria.digital/seo-toronto/":
- elem.click()
- found = 1
- for i in range(2, 24):
- # r = driver.get("https://www.google.ca/search?q=SEO+Toronto&ei="+result+"&start="+str(i*10)+"sa=N")
- check_recaptcha(driver)
- x = driver.find_element_by_xpath('//*[@aria-label="Page ' + str(i) + '"]')
- x.click()
- elems = driver.find_elements_by_xpath("//a[@href]")
- for elem in elems:
- if elem.get_attribute("href") == "https://kanwarmanoria.digital/seo-toronto/":
- elem.click()
- found = 1
- scroll_height = driver.execute_script("return document.body.scrollHeight")
- for x in range(0,scroll_height,int(scroll_height/10)):
- driver.execute_script("window.scrollTo(0, "+str(x)+");")
- time.sleep(5)
- time.sleep(1*60)
- driver.get("https://kanwarmanoria.digital/uncategorized/discovery-application/")
- scroll_height = driver.execute_script("return document.body.scrollHeight")
- for x in range(0,scroll_height,int(scroll_height/10)):
- driver.execute_script("window.scrollTo(0, "+str(x)+");")
- time.sleep(5)
- time.sleep(1*60)
- driver.get("https://kanwarmanoria.digital/citations/")
- for x in range(0,scroll_height,int(scroll_height/10)):
- driver.execute_script("window.scrollTo(0, "+str(x)+");")
- time.sleep(2)
- time.sleep(1*60)
- break
- if found==1:
- break
- time.sleep(2*60)
- driver.close()
- driver.quit()
- return
- if __name__ == '__main__':
- use_proxy = True # Set This Flag
- user_agents_list = []
- user_agents = open("Useragents.txt").readlines()
- for x in user_agents:
- user_agents_list.append(x)
- # print(user_agents_list)
- while True:
- for x in user_agents_list:
- if use_proxy:
- manifest_json = """
- {
- "version": "1.0.0",
- "manifest_version": 2,
- "name": "Chrome Proxy",
- "permissions": [
- "proxy",
- "tabs",
- "unlimitedStorage",
- "storage",
- "<all_urls>",
- "webRequest",
- "webRequestBlocking"
- ],
- "background": {
- "scripts": ["background.js"]
- },
- "minimum_chrome_version":"22.0.0"
- }
- """
- background_js = """
- var config = {
- mode: "fixed_servers",
- rules: {
- singleProxy: {
- scheme: "http",
- host: "%s",
- port: parseInt(%s)
- },
- bypassList: ["localhost"]
- }
- };
- chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
- function callbackFn(details) {
- return {
- authCredentials: {
- username: "%s",
- password: "%s"
- }
- };
- }
- chrome.webRequest.onAuthRequired.addListener(
- callbackFn,
- {urls: ["<all_urls>"]},
- ['blocking']
- );
- """ % (PROXY_HOST, PROXY_PORT, PROXY_USER, PROXY_PASS)
- num_of_clicks = 1 # Change this according to your requirement
- threads = []
- for i in range(0, num_of_clicks):
- t = threading.Thread(target=main,args=[x])
- t.start()
- threads.append(t)
- # time.sleep(5*60) #Enable this for wait 4 minutes
- for thread in threads:
- thread.join()
- time.sleep(1*60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement