def getDriver(self, driverType='firefox'): try: if driverType == 'phantomjs': #capabilities = webdriver.DesiredCapabilities.PHANTOMJS.copy() #capabilities['platform'] = "LINUX" driver = webdriver.PhantomJS('/usr/local/share/phantomjs/bin/phantomjs') else: from selenium.webdriver.firefox.firefox_profile import FirefoxProfile self.dis = Display(visible=0,size=(800,600)) self.dis.start() prx = Proxy() prx.httpProxy= '199.200.120.36:8089' #'112.196.3.254:9064' india prx.proxyType = ProxyType.MANUAL prof = FirefoxProfile('./ffprofile') driver = webdriver.Firefox(proxy=prx, firefox_profile=prof) driver.implicitly_wait(30) driver.set_page_load_timeout(30) print 'started the driver successfully...' return driver except Exception as e: print 'error has occured while starting the driver....' print type(e) print e self.quit() #sys.exit(0) return None
def initialize(driver_url): if len(Config.DESIRED_CAPABILITIES) == 0: options = webdriver.ChromeOptions() options.add_experimental_option('prefs', {'intl.accept_languages': 'ja_JP'}) cap = options.to_capabilities() else: cap = {} for k, v in [cap.split("=") for cap in Config.DESIRED_CAPABILITIES]: k = k.strip("\"'") v = maybe_bool(v.strip("\"'")) merge(cap, construct_dict(k, v)) if Config.HTTP_PROXY or Config.HTTPS_PROXY or Config.NO_PROXY: proxy = Proxy() proxy.sslProxy = Config.HTTPS_PROXY proxy.httpProxy = Config.HTTP_PROXY proxy.noProxy = Config.NO_PROXY proxy.proxyType = ProxyType.MANUAL proxy.add_to_capabilities(cap) driver = webdriver.Remote(command_executor=driver_url, desired_capabilities=cap) return driver
def proxy_settings(ip): proxy = Proxy() proxy.proxy_type = ProxyType.MANUAL proxy.httpProxy = ip capabilities = webdriver.DesiredCapabilities.CHROME proxy.add_to_capabilities(capabilities) return capabilities driver = webdriver.Chrome(desired_capabilities=capabilities)
def setupSelenium(self): """Set up connection with the (remote) selenium server""" self.debug('Setting up selenium') desired_capabilities = DesiredCapabilities.FIREFOX.copy() proxy = Proxy() proxy.proxyType = ProxyType.MANUAL proxy.httpProxy = "localhost:8085" proxy.sslProxy = "localhost:8085" proxy.add_to_capabilities(desired_capabilities) driver = webdriver.Remote( command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=desired_capabilities) return driver
def instantiateBrowser(self): if self.browser == None: chrome_options = webdriver.ChromeOptions() mobile_emulation = {"deviceName": "iPhone 7"} chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--no-sandbox') chrome_options.add_argument("--disable-setuid-sandbox") chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) chrome_options.add_argument('--disable-extensions') chrome_options.add_argument('--no-sandbox') path = config().getConstant("session_path") chrome_options.add_argument("user-data-dir={}".format(path)) if constants.headless: chrome_options.add_argument('--headless') chrome_options.add_argument( '--disable-gpu') # Last I checked this was necessary. capabilities = DesiredCapabilities.CHROME if config().get("use_proxy"): print("using proxy") proxy_address = config().get("proxy_address") proxy = Proxy() proxy.socksPassword = config().get("proxy_password") proxy.socksUsername = config().get("proxy_username") proxy.ftpProxy = proxy_address proxy.httpProxy = proxy_address proxy.sslProxy = proxy_address proxy.proxy_type = {'ff_value': 1, 'string': 'MANUAL'} proxy.add_to_capabilities(capabilities) else: capabilities.pop('proxy', None) self.browser = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities) if True: ## checking ip address print(capabilities) # print("screenshot") # self.browser.get("https://whatismyipaddress.com/") # self.browser.save_screenshot(config().get("bot_account_id") + ".png") AutoLogin(self.browser).login()
def initialize(driver_url): options = webdriver.ChromeOptions() options.add_experimental_option('prefs', {'intl.accept_languages': 'ja_JP'}) cap = options.to_capabilities() if Config.HTTP_PROXY or Config.HTTPS_PROXY or Config.NO_PROXY: proxy = Proxy() proxy.sslProxy = Config.HTTPS_PROXY proxy.httpProxy = Config.HTTP_PROXY proxy.noProxy = Config.NO_PROXY proxy.proxyType = ProxyType.MANUAL proxy.add_to_capabilities(cap) driver = webdriver.Remote( command_executor=driver_url, desired_capabilities=cap) return driver