Advertisement
Guest User

Untitled

a guest
Oct 6th, 2018
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.52 KB | None | 0 0
  1. import os
  2. import zipfile
  3. import time
  4. from selenium import webdriver
  5. from selenium.webdriver import DesiredCapabilities
  6. import threading
  7. import requests
  8. from selenium.webdriver.common.keys import Keys
  9.  
  10. PROXY_HOST = 'x.botproxy.net' # rotating proxy
  11. PROXY_PORT = 8080
  12. PROXY_USER = 'pxu10288-0'
  13. PROXY_PASS = 'DczaZFwD4af*1BBG^is7'
  14. captcha_api_key = "ea5afa171b76afc5df1eb30d68e8cb69"
  15.  
  16.  
  17. def get_chromedriver(use_proxy=False, user_agent=None):
  18. path = os.path.dirname(os.path.abspath(__file__))
  19. chrome_options = webdriver.ChromeOptions()
  20. if use_proxy:
  21. pluginfile = 'proxy_auth_plugin.zip'
  22.  
  23. with zipfile.ZipFile(pluginfile, 'w') as zp:
  24. zp.writestr("manifest.json", manifest_json)
  25. zp.writestr("background.js", background_js)
  26. chrome_options.add_extension(pluginfile)
  27. if user_agent:
  28. chrome_options.add_argument('--user-agent=%s' % user_agent)
  29. driver = webdriver.Chrome(
  30. os.path.join(path, 'chromedriver'),
  31. chrome_options=chrome_options)
  32. return driver
  33.  
  34.  
  35. def check_recaptcha(driver):
  36. if "recaptcha" in driver.page_source:
  37. recaptcha = driver.find_elements_by_xpath("//*[@data-sitekey]")
  38. for a in recaptcha:
  39. g_key = a.get_attribute("data-sitekey")
  40. print(g_key)
  41. page_url = driver.current_url
  42. url = "http://2captcha.com/in.php?key=" + captcha_api_key + "&method=userrecaptcha&googlekey=" + g_key + "&json=1&pageurl=" + page_url
  43. r1 = requests.get(url = url)
  44. print("Request Made")
  45. captcha_id = eval(r1.text)["request"]
  46. while True:
  47. answer = requests.get("http://2captcha.com/res.php?key="+captcha_api_key+"&action=get&json=1&id="+captcha_id)
  48. if eval(answer.text)["request"] == "CAPCHA_NOT_READY":
  49. print("Captcha Not Ready")
  50. time.sleep(2)
  51. continue
  52. else:
  53. print("Captcha Ready.Breaking")
  54. print(answer.text)
  55. break
  56. ans = eval(answer.text)
  57. js_exe = "document.getElementById('g-recaptcha-response').innerHTML = "+"'"+ans["request"]+"'"
  58. print(js_exe)
  59. driver.execute_script(js_exe)
  60. print("Script Executed")
  61. driver.find_element_by_name("submit").click()
  62. else:
  63. print("Recaptcha Didnt Appear")
  64. return driver
  65.  
  66.  
  67. def main(user_agent= None):
  68.  
  69. # drivers.append(driver)
  70. key_words = ["SEO Toronto"]
  71. for word in key_words:
  72. temp_word = word.replace(" ", "+")
  73. driver = get_chromedriver(use_proxy=use_proxy, user_agent=user_agent)
  74. data = driver.get("https://www.google.ca/search?q="+temp_word)
  75. check_recaptcha(driver)
  76. elems = driver.find_elements_by_xpath("//a[@href]")
  77. found = 0
  78. for elem in elems:
  79. if elem.get_attribute("href") == "https://kanwarmanoria.digital/seo-toronto/":
  80. elem.click()
  81. found = 1
  82. for i in range(2, 24):
  83. # r = driver.get("https://www.google.ca/search?q=SEO+Toronto&ei="+result+"&start="+str(i*10)+"sa=N")
  84. check_recaptcha(driver)
  85. x = driver.find_element_by_xpath('//*[@aria-label="Page ' + str(i) + '"]')
  86. x.click()
  87. elems = driver.find_elements_by_xpath("//a[@href]")
  88. for elem in elems:
  89. if elem.get_attribute("href") == "https://kanwarmanoria.digital/seo-toronto/":
  90. elem.click()
  91. found = 1
  92. scroll_height = driver.execute_script("return document.body.scrollHeight")
  93. for x in range(0,scroll_height,int(scroll_height/10)):
  94. driver.execute_script("window.scrollTo(0, "+str(x)+");")
  95. time.sleep(5)
  96. time.sleep(1*60)
  97. driver.get("https://kanwarmanoria.digital/uncategorized/discovery-application/")
  98. scroll_height = driver.execute_script("return document.body.scrollHeight")
  99. for x in range(0,scroll_height,int(scroll_height/10)):
  100. driver.execute_script("window.scrollTo(0, "+str(x)+");")
  101. time.sleep(5)
  102. time.sleep(1*60)
  103. driver.get("https://kanwarmanoria.digital/citations/")
  104. for x in range(0,scroll_height,int(scroll_height/10)):
  105. driver.execute_script("window.scrollTo(0, "+str(x)+");")
  106. time.sleep(2)
  107. time.sleep(1*60)
  108. break
  109.  
  110. if found==1:
  111. break
  112. time.sleep(2*60)
  113. driver.close()
  114. driver.quit()
  115. return
  116.  
  117.  
  118. if __name__ == '__main__':
  119. use_proxy = True # Set This Flag
  120. user_agents_list = []
  121. user_agents = open("Useragents.txt").readlines()
  122. for x in user_agents:
  123. user_agents_list.append(x)
  124. # print(user_agents_list)
  125. while True:
  126. for x in user_agents_list:
  127. if use_proxy:
  128. manifest_json = """
  129. {
  130. "version": "1.0.0",
  131. "manifest_version": 2,
  132. "name": "Chrome Proxy",
  133. "permissions": [
  134. "proxy",
  135. "tabs",
  136. "unlimitedStorage",
  137. "storage",
  138. "<all_urls>",
  139. "webRequest",
  140. "webRequestBlocking"
  141. ],
  142. "background": {
  143. "scripts": ["background.js"]
  144. },
  145. "minimum_chrome_version":"22.0.0"
  146. }
  147. """
  148. background_js = """
  149. var config = {
  150. mode: "fixed_servers",
  151. rules: {
  152. singleProxy: {
  153. scheme: "http",
  154. host: "%s",
  155. port: parseInt(%s)
  156. },
  157. bypassList: ["localhost"]
  158. }
  159. };
  160.  
  161. chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
  162.  
  163. function callbackFn(details) {
  164. return {
  165. authCredentials: {
  166. username: "%s",
  167. password: "%s"
  168. }
  169. };
  170. }
  171.  
  172. chrome.webRequest.onAuthRequired.addListener(
  173. callbackFn,
  174. {urls: ["<all_urls>"]},
  175. ['blocking']
  176. );
  177. """ % (PROXY_HOST, PROXY_PORT, PROXY_USER, PROXY_PASS)
  178.  
  179. num_of_clicks = 1 # Change this according to your requirement
  180. threads = []
  181. for i in range(0, num_of_clicks):
  182. t = threading.Thread(target=main,args=[x])
  183. t.start()
  184. threads.append(t)
  185. # time.sleep(5*60) #Enable this for wait 4 minutes
  186. for thread in threads:
  187. thread.join()
  188. time.sleep(1*60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement