Advertisement
Guest User

Untitled

a guest
Mar 12th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  3. from selenium.webdriver.common.proxy import Proxy, ProxyType
  4. import os
  5. import random
  6. import traceback
  7. import zipfile
  8.  
  9. proxy_filename = "proxy_5s.txt"
  10. if os.path.getsize(proxy_filename):
  11. _proxy_list_file = list(filter(None, (line.rstrip() for line in open(proxy_filename))))
  12.  
  13. PROXY = random.choice(_proxy_list_file)
  14.  
  15. PROXY = ":".join([PROXY.split(':')[0], PROXY.split(':')[1]])
  16. auth = "paulohot12749:h4h3p9ppv5"
  17.  
  18. capabilities = DesiredCapabilities.CHROME.copy()
  19. chromeOptionsRemote = webdriver.ChromeOptions()
  20. chromeOptionsRemote.add_argument("--start-maximized")
  21. chromeOptionsRemote.add_argument("--disable-session-crashed-bubble")
  22. chromeOptionsRemote.add_argument("--ignore-ssl-errors=true")
  23. chromeOptionsRemote.add_argument("--ssl-protocol=all")
  24. # chromeOptionsRemote.add_argument("--proxy-server=https://{}".format(PROXY))
  25. # chromeOptionsRemote.add_argument("--proxy-auth={}".format(auth))
  26.  
  27.  
  28. manifest_json = """
  29. {
  30. "version": "1.0.0",
  31. "manifest_version": 2,
  32. "name": "Chrome Proxy",
  33. "permissions": [
  34. "proxy",
  35. "tabs",
  36. "unlimitedStorage",
  37. "storage",
  38. "<all_urls>",
  39. "webRequest",
  40. "webRequestBlocking"
  41. ],
  42. "background": {
  43. "scripts": ["background.js"]
  44. },
  45. "minimum_chrome_version":"22.0.0"
  46. }
  47. """
  48.  
  49. background_js = """
  50. var config = {
  51. mode: "fixed_servers",
  52. rules: {
  53. singleProxy: {
  54. scheme: "http",
  55. host: "%s",
  56. port: parseInt(%s)
  57. },
  58. bypassList: ["localhost"]
  59. }
  60. };
  61.  
  62. chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
  63.  
  64. function callbackFn(details) {
  65. return {
  66. authCredentials: {
  67. username: "%s",
  68. password: "%s"
  69. }
  70. };
  71. }
  72.  
  73. chrome.webRequest.onAuthRequired.addListener(
  74. callbackFn,
  75. {urls: ["<all_urls>"]},
  76. ['blocking']
  77. );
  78. """ % (PROXY.split(':')[0], PROXY.split(':')[1], auth.split(':')[0], auth.split(':')[1])
  79.  
  80. # driver = None
  81. try:
  82. pluginfile = 'proxy_auth_plugin.zip'
  83.  
  84. with zipfile.ZipFile(pluginfile, 'w') as zp:
  85. zp.writestr("manifest.json", manifest_json)
  86. zp.writestr("background.js", background_js)
  87. chromeOptionsRemote.add_extension(pluginfile)
  88. chromeOptionsRemote.add_extension('easy_webrtc.crx')
  89.  
  90. driver = webdriver.Remote(options=chromeOptionsRemote, command_executor='http://78.31.71.191:4444/wd/hub',
  91. desired_capabilities=capabilities)
  92. driver.set_page_load_timeout(30)
  93. driver.implicitly_wait(15)
  94. driver.get('https://www.whoer.net/')
  95.  
  96. driver.save_screenshot(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'screen.png'))
  97.  
  98. print(driver.current_url)
  99.  
  100. driver.execute_script("window.scrollTo(0, 600);")
  101. driver.save_screenshot(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'screen2.png'))
  102.  
  103. ip_elem = driver.find_element_by_xpath("//strong[@data-clipboard-target]")
  104.  
  105. print(ip_elem.text)
  106.  
  107. except Exception as e:
  108. traceback.print_exc()
  109. driver.save_screenshot(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'screen1.png'))
  110. finally:
  111. driver.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement