Exemple #1
0
def get_webdriver():
    options = webdriver.ChromeOptions()
    options.add_argument('window-size=1920x1080')
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')

    # Configure Proxy option
    proxy = Proxy()

    if Settings.socks_proxy is None and Settings.https_proxy is None and Settings.https_proxy is None:
        proxy.proxy_type = ProxyType.DIRECT
    else:
        proxy.proxy_type = ProxyType.MANUAL

        if Settings.socks_proxy is not None:
            options.add_argument("--proxy-server=" +
                                 Settings.get_full_socks_proxy())
        else:
            if Settings.http_proxy is not None:
                proxy.http_proxy = Settings.http_proxy
            if Settings.https_proxy is not None:
                proxy.ssl_proxy = Settings.https_proxy

    # Configure capabilities
    capabilities = webdriver.DesiredCapabilities.CHROME
    proxy.add_to_capabilities(capabilities)

    return webdriver.Chrome(options=options, desired_capabilities=capabilities)
Exemple #2
0
def testCanNotChangeInitializedProxyType():
    proxy = Proxy(raw={'proxyType': 'direct'})
    with pytest.raises(Exception):
        proxy.proxy_type = ProxyType.SYSTEM

    proxy = Proxy(raw={'proxyType': ProxyType.DIRECT})
    with pytest.raises(Exception):
        proxy.proxy_type = ProxyType.SYSTEM
Exemple #3
0
def testCanNotChangeInitializedProxyType():
    proxy = Proxy(raw={'proxyType': 'direct'})
    with pytest.raises(Exception):
        proxy.proxy_type = ProxyType.SYSTEM

    proxy = Proxy(raw={'proxyType': ProxyType.DIRECT})
    with pytest.raises(Exception):
        proxy.proxy_type = ProxyType.SYSTEM
Exemple #4
0
def test_can_not_change_initialized_proxy_type():
    proxy = Proxy(raw={'proxyType': 'direct'})
    with pytest.raises(Exception):
        proxy.proxy_type = ProxyType.SYSTEM

    proxy = Proxy(raw={'proxyType': ProxyType.DIRECT})
    with pytest.raises(Exception):
        proxy.proxy_type = ProxyType.SYSTEM
Exemple #5
0
    def testCanNotChangeInitializedProxyType(self):
        proxy = Proxy(raw={'proxyType': 'direct'})
        try:
            proxy.proxy_type = ProxyType.SYSTEM
            raise Exception("Change of already initialized proxy type should raise exception")
        except Exception as e:
            pass

        proxy = Proxy(raw={'proxyType': ProxyType.DIRECT})
        try:
            proxy.proxy_type = ProxyType.SYSTEM
            raise Exception("Change of already initialized proxy type should raise exception")
        except Exception as e:
            pass
Exemple #6
0
    def _setup_driver(self):
        proxy = Proxy()
        if 'http' in self.proxy:
            proxy.proxy_type = ProxyType.MANUAL
            proxy.http_proxy = self.proxy['http']
        if 'https' in self.proxy:
            proxy.proxy_type = ProxyType.MANUAL
            proxy.ssl_proxy = self.proxy['https']

        if proxy.proxy_type != ProxyType.MANUAL:
            proxy.proxy_type = ProxyType.DIRECT

        capa = self._build_capabilities()
        proxy.add_to_capabilities(capa)

        options = self._build_options()
        # TODO some browsers don't need headless
        # TODO handle different proxy setting?
        options.set_headless(self.HEADLESS)

        if self.DRIVER is webdriver.Firefox:
            if self.responses_dirname and not os.path.isdir(
                    self.responses_dirname):
                os.makedirs(self.responses_dirname)

            options.profile = DirFirefoxProfile(self.responses_dirname)
            if self.responses_dirname:
                capa['profile'] = self.responses_dirname
            self.driver = self.DRIVER(options=options, capabilities=capa)
        elif self.DRIVER is webdriver.Chrome:
            self.driver = self.DRIVER(options=options,
                                      desired_capabilities=capa)
        elif self.DRIVER is webdriver.PhantomJS:
            if self.responses_dirname:
                if not os.path.isdir(self.responses_dirname):
                    os.makedirs(self.responses_dirname)
                log_path = os.path.join(self.responses_dirname, 'selenium.log')
            else:
                log_path = NamedTemporaryFile(prefix='weboob_selenium_',
                                              suffix='.log',
                                              delete=False).name

            self.driver = self.DRIVER(desired_capabilities=capa,
                                      service_log_path=log_path)
        else:
            raise NotImplementedError()

        if self.WINDOW_SIZE:
            self.driver.set_window_size(*self.WINDOW_SIZE)
def proxied_driver(addresses, driver_type="chrome", co=None):
    assert len(addresses) > 0, "At least one proxy address must be provided"

    prox = Proxy()
    prox.proxy_type = ProxyType.MANUAL
    addr = random.choice(addresses)
    prox.http_proxy = addr
    prox.ssl_proxy = addr

    assert driver_type in ["chrome",
                           "firefox"], "proxy_type must be chrome or firefox "
    if driver_type == "chrome":
        capabilities = webdriver.DesiredCapabilities.CHROME
        prox.add_to_capabilities(capabilities)
        driver = webdriver.Chrome(chrome_options=co,
                                  desired_capabilities=capabilities)
        # 참고로 이런 .method의 번거로움이 python 단점 중 하나. 간단한 설정이어야 하는게 이상하게 구성하게됨
    elif driver_type == "firefox":
        capabilities = DesiredCapabilities.FIREFOX
        prox.add_to_capabilities(capabilities)
        driver = webdriver.Firefox(
            firefox_options=co,
            desired_capabilities=capabilities,
            executable_path="/usr/local/bin/geckodriver")

    return driver
Exemple #8
0
    def get_capabilities(self):
        capabilities = DesiredCapabilities.FIREFOX.copy()
        # capabilities = DesiredCapabilities.CHROME.copy()
        # print('get_capabilities')
        proxy = self.profile.proxy

        if proxy is None or not proxy.active:
            # use random default proxy
            proxies = models.Proxy.objects.filter(active=True,
                                                  default=True).all()
            if proxies:
                proxy = random.choice(proxies)
            else:
                proxy = None

        if proxy:
            # print('setting a proxy')
            # print(proxy)
            prox = Proxy()
            prox.proxy_type = ProxyType.MANUAL
            if proxy.proxy_type == proxy.HTTP:
                # print('HTTP proxy')
                prox.http_proxy = f'{proxy.ip}:{proxy.port}'
                prox.ssl_proxy = f'{proxy.ip}:{proxy.port}'
                prox.ftp_proxy = f'{proxy.ip}:{proxy.port}'
            elif proxy.proxy_type == proxy.SOCKS:
                # print('Socks proxy')
                prox.socks_proxy = f'{proxy.ip}:{proxy.port}'
                prox.socks_username = proxy.username
                prox.socks_password = proxy.password

            prox.add_to_capabilities(capabilities)

        # print(capabilities)
        return capabilities
Exemple #9
0
def getGoogleChromeDriver(fullproxy):
    try:
        proxy = fullproxy.split(' ')[0]
        conditionalPrint("proxy used : " + proxy)
        WINDOW_SIZE = "1920,1080"
        option = webdriver.ChromeOptions()
        option.add_argument("--incognito")
        #option.add_argument("--disable-gpu")
        #option.add_argument("--disable-infobars")
        #option.add_argument("--disable-notifications")
        #option.add_argument("--disable-extensions")
        if hideBrowser == "YES":
            option.add_argument("--headless")
            option.add_argument("--window-size=%s" % WINDOW_SIZE)

        prox = Proxy()
        prox.proxy_type = ProxyType.MANUAL
        prox.http_proxy = proxy
        prox.socks_proxy = proxy
        prox.ssl_proxy = proxy

        capabilities = webdriver.DesiredCapabilities.CHROME
        prox.add_to_capabilities(capabilities)
        browser = webdriver.Chrome(
            executable_path="C:\\webdrivers\\chromedriver.exe",
            chrome_options=option,
            desired_capabilities=capabilities)
        #browser.set_window_position(-10000, 0)
        return browser
    except Exception:
        LogError(traceback, "fullproxy = " + fullproxy)
    return None
Exemple #10
0
def get_browser(PROXY):

    import os
    luminati_host = os.environ.get('LUMINATI_HOST')
    luminati_port = os.environ.get('LUMINATI_PORT')
    PROXY = 'http://' + luminati_host + ':' + luminati_port
    print(PROXY)

    proxy = Proxy()
    proxy.http_proxy = PROXY
    proxy.ftp_proxy = PROXY
    proxy.sslProxy = PROXY
    proxy.no_proxy = "localhost" #etc... ;)
    proxy.proxy_type = ProxyType.MANUAL

    capabilities = webdriver.DesiredCapabilities.CHROME

    proxy.add_to_capabilities(capabilities)
    # path = '/home/balu/balu/work/Courses/luminati+selinium/testapp/app/helper_files/chromedriver'
    # driver = webdriver.Chrome(executable_path = path, desired_capabilities=capabilities)
    
    driver = webdriver.Remote("http://172.20.128.1:4444/wd/hub", desired_capabilities=capabilities)
    url = 'https://lumtest.com/myip.json'
    driver.get(url)
    print(driver.page_source)
    
    return driver
Exemple #11
0
def CreateBrowser(proxy, head=False, window=False, ua=False):
    if proxy:
        prox = Proxy()
        prox.proxy_type = ProxyType.MANUAL
        prox.ssl_proxy = proxy
        capabilities = webdriver.DesiredCapabilities.CHROME
        prox.add_to_capabilities(capabilities)

    # Set random user agent
    opts = Options()
    if ua:
        ua = UserAgent()
        agent = ua.chrome
        opts.add_argument("user-agent=" + agent)
    if not head:
        opts.add_argument("--headless")
    if window:
        opts.add_argument("--window-size=" + window)
    else:
        opts.add_argument("--window-size=%s" % "1920,1080")

    if proxy:
        _browser = webdriver.Chrome(options=opts,
                                    desired_capabilities=capabilities)
    else:
        _browser = webdriver.Chrome(options=opts)
    return _browser
Exemple #12
0
    def create_instances(self):
        for _proxy in self.proxies:
            proxy = _proxy.proxy
            service_args = []
            # service_args.append('--proxy={}:{}'.format(proxy.ip, proxy.port))

            if proxy.username and proxy.password:
                service_args.append('--proxy-auth={}:{}'.format(
                    proxy.username, proxy.password))

            capabilities = DesiredCapabilities.PHANTOMJS
            capabilities[
                'phantomjs.page.settings.resourceTimeout'] = self.max_delay_limit * 1000

            _proxy_ = Proxy()
            _proxy_.proxy_type = ProxyType.MANUAL
            _proxy_.http_proxy = '{}:{}'.format(proxy.ip, proxy.port)
            _proxy_.socks_proxy = '{}:{}'.format(proxy.ip, proxy.port)
            _proxy_.ssl_proxy = '{}:{}'.format(proxy.ip, proxy.port)
            _proxy_.add_to_capabilities(capabilities)

            driver = webdriver.PhantomJS(
                service_args=service_args,
                desired_capabilities=capabilities,
                service_log_path='/tmp/ghostdriver.log')

            driver.set_window_size(1120, 1080)
            driver.set_page_load_timeout(self.max_delay_limit)

            self.multi_instances.append(driver)
Exemple #13
0
def get_browser():
    # @todo add windows path
    if platform.system() == "Darwin":
        os.environ["webdriver.chrome.driver"] = os.path.expanduser(
            "~"
        ) + '/Library/Application Support/ZAP/webdriver/macos/64/chromedriver'
    else:
        os.environ["webdriver.chrome.driver"] = os.path.expanduser(
            "~") + '/.ZAP/webdriver/linux/64/chromedriver'

    proxy = Proxy()
    proxy.proxy_type = ProxyType.MANUAL
    proxy.http_proxy = "127.0.0.1:8080"
    proxy.socks_proxy = "127.0.0.1:8080"
    proxy.ssl_proxy = "127.0.0.1:8080"

    capabilities = webdriver.DesiredCapabilities.CHROME
    proxy.add_to_capabilities(capabilities)

    options = webdriver.ChromeOptions()
    options.add_argument('--ignore-certificate-errors')
    options.add_argument("--test-type")
    return webdriver.Chrome(
        executable_path=os.environ["webdriver.chrome.driver"],
        chrome_options=options,
        desired_capabilities=capabilities)
Exemple #14
0
    def get_phantomjs_browser(
        self,
        proxy=None,
        timeout=15,
    ):
        """
        创建一个phantomjs浏览器

        :param proxy: String "ip:port"

        :param timeout: Int

        :return: Phantomjs.Browser 浏览器对象
        """
        capabilities = webdriver.DesiredCapabilities.PHANTOMJS
        capabilities['phantomjs.page.settings.userAgent'] = random.choice(
            USER_AGENTS)
        capabilities["phantomjs.page.settings.loadImages"] = False
        if proxy:
            prox = Proxy()
            prox.proxy_type = ProxyType.MANUAL
            prox.http_proxy = proxy
            prox.socks_proxy = proxy
            prox.ssl_proxy = proxy
            prox.add_to_capabilities(capabilities)

        browser = webdriver.PhantomJS(desired_capabilities=capabilities)
        browser.maximize_window()
        browser.set_page_load_timeout(timeout)
        return browser
    def __init__(self, songUrl, proxy_url):
        self.songUrl = songUrl
        self.id = -1
        self.name = ''
        self.album_id = -1
        self.comments_num = -1
        self.similar_song_ids = []
        self.artists = []

        chrome_options = Options()
        prox = Proxy()
        prox.proxy_type = ProxyType.MANUAL
        prox.http_proxy = proxy_url
        prox.ssl_proxy = proxy_url
        # prox.socks_proxy = proxy_url
        capabilities = webdriver.DesiredCapabilities.CHROME
        prox.add_to_capabilities(capabilities)
        chrome_options.add_argument('--headless')
        # chrome_options.add_argument('user-agent={0}'.format(random.choice(uas)))
        # chrome_options.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
        if config_is_ubuntu:
            chrome_options.add_argument('--no-sandbox')
            chrome_options.add_argument('--disable-dev-shm-usage')
        # chrome_options.add_argument('--proxy-server=http://111.222.141.127:8118')
        # chrome_options.add_argument('--proxy-server={}'.format(proxy_url))
        # chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
        # debug_print_thread("we are using proxy sever with url " + proxy_url)
        # chrome_options.add_argument('--proxy-server=http://114.98.27.147:4216')

        self.driver = webdriver.Chrome(config_chrome_path,
                                       options=chrome_options)
def proxy_driver(PROXIES, co=co):
    prox = Proxy()
    ua = UserAgent()
    while True:
        if PROXIES:
            pxy = PROXIES[-1]
            break
        else:
            print("--- Proxies used up (%s)" % len(PROXIES))
            PROXIES = get_proxies()

    prox.proxy_type = ProxyType.MANUAL
    prox.http_proxy = pxy
    #prox.socks_proxy = pxy
    prox.ssl_proxy = pxy

    capabilities = dict(DesiredCapabilities.CHROME)
    capabilities["chrome.page.settings.userAgent"] = (ua.random)
    prox.add_to_capabilities(capabilities)
    service_args = ['--ssl-protocol=any', '--ignore-ssl-errors=true']
    driver = webdriver.Chrome("chromedriver.exe",
                              options=co,
                              desired_capabilities=capabilities,
                              service_args=service_args)

    return driver
Exemple #17
0
def get_browser(url, proxy=""):
    from selenium import webdriver
    from selenium.webdriver.common.proxy import Proxy, ProxyType

    if proxy == "":
        browser = webdriver.Chrome(
        )  #replace with .Firefox(), or with the browser of your choice

    else:
        prox = Proxy()
        prox.proxy_type = ProxyType.MANUAL
        prox.https_proxy = proxy
        #prox.https_proxy = proxy

        #prox.socks_proxy = "ip_addr:port"
        #prox.ssl_proxy = "ip_addr:port"

        capabilities = webdriver.DesiredCapabilities.CHROME
        prox.add_to_capabilities(capabilities)

        browser = webdriver.Chrome(desired_capabilities=capabilities)

    browser.get(url)  #navigate to the page
    #browser.close()
    return browser
    def __init__(self, email, password, category):
        super().__init__()

        self.email = email
        self.password = password
        self.category = category
        self.count = 1

        logging.basicConfig(
            handlers=[logging.FileHandler('./Logs/scraper.log', 'w', 'utf-8')],
            format=': %(asctime)s : %(levelname)s : %(message)s : ',
        )

        self.logger = logging.getLogger()
        self.logger.setLevel(logging.INFO)

        self.links = link_generator.generate(self.category)
        self.proxy = proxy_generator.get_proxy()
        self.scrapedData = []

        try:
            prox = Proxy()
            prox.proxy_type = ProxyType.MANUAL
            prox.http_proxy = self.proxy
            capabilities = webdriver.DesiredCapabilities.CHROME
            prox.add_to_capabilities(capabilities)
            self.driver = webdriver.Chrome(ChromeDriverManager().install(),
                                           options=chrome_settings,
                                           desired_capabilities=capabilities)

        except Exception as e:
            self.logger.critical("Driver Error: " + str(e))
Exemple #19
0
 def _start_proxy_(self, ip: str, port: int):
     prox = Proxy()
     endpoint = ip + ":" + str(port)
     prox.proxy_type = ProxyType.MANUAL
     prox.http_proxy = endpoint
     prox.socks_proxy = endpoint
     prox.ssl_proxy = endpoint
Exemple #20
0
 def __get_driver_desired_capabilities(self):
     prox = Proxy()
     prox.proxy_type = ProxyType.MANUAL
     prox.http_proxy = "103.109.58.245:8080"
     capabilities = webdriver.DesiredCapabilities.CHROME
     prox.add_to_capabilities(capabilities)
     return capabilities
Exemple #21
0
def main():
    """
        This is the entry for the command which makes it convenient to install the proxy certificate
    """
    commandArgs = sys.argv[1:]

    proxyPort = findFreePort()

    proxyThread = threading.Thread(target=runProxy,
                                   args=[proxyPort],
                                   daemon=True)
    proxyThread.start()

    capabilities = webdriver.DesiredCapabilities.CHROME
    capabilities['loggingPrefs'] = {'browser': 'ALL'}
    proxyConfig = Proxy()
    proxyConfig.proxy_type = ProxyType.MANUAL
    proxyConfig.http_proxy = f"localhost:{proxyPort}"
    proxyConfig.add_to_capabilities(capabilities)

    driver = webdriver.Chrome(desired_capabilities=capabilities)

    driver.get("http://mitm.it/")

    print(
        "Please kill the command with Ctrl-C or (Cmd-C on macOS) when you are finished installing the certificates. Timeout in 600 seconds..."
    )

    timeout = 600
    if len(commandArgs) > 0:
        timeout = int(str(commandArgs[0]))

    time.sleep(timeout)
Exemple #22
0
def load_page(source):

    prox = Proxy()
    prox.proxy_type = ProxyType.MANUAL
    prox.http_proxy = "127.0.0.1:9090"
    prox.socks_proxy = "127.0.0.1:9090"
    prox.ssl_proxy = "127.0.0.1:9090"

    capabilities = webdriver.DesiredCapabilities.CHROME
    prox.add_to_capabilities(capabilities)

    driver = webdriver.Chrome(desired_capabilities=capabilities)
    driver.get(source)

    navigationStart = driver.execute_script(
        "return window.performance.timing.navigationStart")
    responseStart = driver.execute_script(
        "return window.performance.timing.responseStart")
    domComplete = driver.execute_script(
        "return window.performance.timing.domComplete")

    backendPerformance = responseStart - navigationStart
    frontendPerformance = domComplete - responseStart

    print "Back End: %s" % backendPerformance
    print "Front End: %s" % frontendPerformance

    driver.quit()
Exemple #23
0
def initialize_browser() -> object:
    chrome_options = Options()
    chrome_options.add_argument('--window-size=1920x1080')
    chrome_options.add_argument('--ignore-certificate-errors')
    chrome_options.add_argument(
        'user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 '
        'Safari/537.36')
    proxy_url = "127.0.0.1:24001"
    proxy = Proxy()
    proxy.proxy_type = ProxyType.MANUAL
    proxy.http_proxy = proxy_url
    proxy.ssl_proxy = proxy_url
    capabilities = webdriver.DesiredCapabilities.CHROME
    proxy.add_to_capabilities(capabilities)
    if is_development():
        return webdriver.Chrome('./bin/chromedriver.exe',
                                chrome_options=chrome_options,
                                desired_capabilities=capabilities)
    else:
        chrome_options.add_argument('--data-path=/tmp/data-path')
        chrome_options.add_argument('--homedir=/tmp')
        chrome_options.add_argument('--disk-cache-dir=/tmp/cache-dir')
        chrome_options.add_argument('--user-data-dir=/tmp/user-data')
        chrome_options.add_argument('--hide-scrollbars')
        chrome_options.add_argument('--enable-logging')
        chrome_options.add_argument('--log-level=0')
        chrome_options.add_argument('--v=99')
        chrome_options.add_argument('--single-process')
        chrome_options.add_argument('--disable-dev-shm-usage')
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--disable-gpu')
        return webdriver.Chrome(chrome_options=chrome_options,
                                desired_capabilities=capabilities)
Exemple #24
0
    def __init__(self, proxy):
        """
        Initialize the web driver.
        """

        if proxy:
            PROXY = self.get_proxy()

            custom_proxy = Proxy()
            custom_proxy.proxy_type = ProxyType.MANUAL
            custom_proxy.ssl_proxy = PROXY

            capabilities = webdriver.DesiredCapabilities.CHROME
            custom_proxy.add_to_capabilities(capabilities)

            self.driver = webdriver.Chrome(
                ChromeDriverManager().install(),
                desired_capabilities=capabilities
            )

        else:
            options = Options()
            options.add_argument('--no-sandbox')
            options.add_argument('--disable-dev-shm-usage')

            self.driver = webdriver.Chrome(
                ChromeDriverManager().install(),
                chrome_options=options
            )
Exemple #25
0
def make_headless_browser(custom_options={}):
    """无头浏览器"""
    # 使用系统代理
    proxy = Proxy()
    proxy.proxy_type = 'SYSTEM'

    fp = FirefoxProfile()

    options = Options()
    # 无头浏览器
    options.headless = True
    # 禁用gpu加速
    options.add_argument('--disable-gpu')
    # 网页加载模式
    # options.page_load_strategy = 'eager'

    default_options = {}
    default_options.update(custom_options)

    log_path = data_root('geckordriver') / f'{os.getpid()}.log'

    return webdriver.Firefox(
        options=options,
        seleniumwire_options=default_options,
        proxy=proxy,
        firefox_profile=fp,
        service_log_path=log_path,
        executable_path=DEFAULT_CONFIG['geckodriver_path'])
Exemple #26
0
def __open_browser(context):
    chrm = context.config.userdata['chromedriver_path']

    try:
        # if there is a proxy, we'll use it.  Otherwise, we won't.
        requests.get("http://localhost:8888", timeout=0.01)

        # if there was no exception, we continue here.
        PROXY = "localhost:8888"

        proxy = Proxy()
        proxy.proxy_type = ProxyType.MANUAL
        proxy.http_proxy = PROXY

        capabilities = webdriver.DesiredCapabilities.CHROME
        proxy.add_to_capabilities(capabilities)

        if (chrm):
            context.driver = webdriver.Chrome(
                desired_capabilities=capabilities, executable_path=chrm)
        else:
            context.driver = webdriver.Chrome(
                desired_capabilities=capabilities)
        return context.driver
    except:
        if (chrm):
            context.driver = webdriver.Chrome(executable_path=chrm)
        else:
            context.driver = webdriver.Chrome()
        return context.driver
Exemple #27
0
def get_driver(proxy=False, login=False):
    if proxy:
        #set up proxy
        prox = Proxy()
        prox.proxy_type = ProxyType.MANUAL
        prox.http_proxy = "10.211.55.4:808"
        capabilities = webdriver.DesiredCapabilities.CHROME
        prox.add_to_capabilities(capabilities)
    else:
        capabilities = webdriver.DesiredCapabilities.CHROME
    chrome_options = webdriver.ChromeOptions()
    #chrome_options.add_argument('--headless')
    #chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument(
        '--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36'
    )
    chrome_options.add_argument('--window-size=1024,768')
    driver = webdriver.Chrome('./chromedriver',
                              chrome_options=chrome_options,
                              desired_capabilities=capabilities)
    if login:
        driver.get(login_url)
        name = driver.find_element_by_xpath(xpaths.login_username)
        name.send_keys(username)
        pw = driver.find_element_by_xpath(xpaths.login_password)
        pw.send_keys(password)
        login = driver.find_element_by_xpath(xpaths.login_btn)
        login.click()
    return driver
Exemple #28
0
def setup_proxy(proxy):
    proxy_config = Proxy()
    proxy_config.proxy_type = ProxyType.MANUAL
    proxy_config.http_proxy = proxy
    proxy_config.ssl_proxy = proxy
    capabilities = webdriver.DesiredCapabilities.CHROME
    proxy_config.add_to_capabilities(capabilities)
    return proxy_config
Exemple #29
0
 def _add_proxy_support(self, capabilities):
     if "RX_PROXY" in os.environ:
         proxy = Proxy()
         proxy.proxy_type = ProxyType.MANUAL
         proxy.http_proxy = os.environ.get("RX_PROXY")
         proxy.socks_proxy = os.environ.get("RX_PROXY")
         proxy.ssl_proxy = os.environ.get("RX_PROXY")
         proxy.add_to_capabilities(capabilities)
Exemple #30
0
def chromeShot(url, f, p=""):
    whine("Taking Screenshot   : " + url, "debug")

    prox = Proxy()
    prox.proxy_type = ProxyType.MANUAL

    if p:
        prox.proxy_type = ProxyType.MANUAL
        prox.http_proxy = p
        prox.ssl_proxy = p

    capabilities = webdriver.DesiredCapabilities.CHROME
    prox.add_to_capabilities(capabilities)

    chrome_options = Options()
    chrome_options.add_argument("--headless")
    chrome_options.add_argument("--disable-logging")
    chrome_options.add_argument("--log-level=3")
    chrome_options.add_argument("--window-size=1920x1080")
    chrome_options.add_argument("--no-sandbox")
    chrome_options.add_argument("--user-data-dir /tmp")
    chrome_options.add_argument('--ignore-certificate-errors')

    chrome_driver = "/usr/bin/chromedriver"

    # Copy to dedicated screenshot directory
    sDir = os.path.dirname(f)
    sDir = os.path.dirname(sDir)
    sDir += "/ScreenShots/"
    if not os.path.exists(sDir):
        os.makedirs(sDir)

    sf = sDir + urllib.parse.quote(url, safe='') + ".png"

    try:
        driver = webdriver.Chrome(options=chrome_options,
                                  executable_path=chrome_driver,
                                  desired_capabilities=capabilities)
        driver.set_page_load_timeout(10)
        driver.get(url)
        driver.get_screenshot_as_file(f)
        # Copy to dedicated screenshot directory
        copy2(f, sf)
        driver.quit()
    except Exception as e:
        whine("screenshot Error:" + str(e), "debug")
Exemple #31
0
    def testCanNotChangeInitializedProxyType(self):
        proxy = Proxy(raw={'proxyType': 'direct'})
        try:
            proxy.proxy_type = ProxyType.SYSTEM
            raise Exception(
                "Change of already initialized proxy type should raise exception"
            )
        except Exception as e:
            pass

        proxy = Proxy(raw={'proxyType': ProxyType.DIRECT})
        try:
            proxy.proxy_type = ProxyType.SYSTEM
            raise Exception(
                "Change of already initialized proxy type should raise exception"
            )
        except Exception as e:
            pass
Exemple #32
0
 def set_selenium_proxy(self, selenium_proxy):
     proxy = Proxy()
     proxy.http_proxy = selenium_proxy
     proxy.ftp_proxy = selenium_proxy
     proxy.sslProxy = selenium_proxy
     proxy.no_proxy = None
     proxy.proxy_type = ProxyType.MANUAL
     proxy.add_to_capabilities(self.capabilities)
     self.capabilities["acceptSslCerts"] = True
Exemple #33
0
    def _setup_driver(self):
        proxy = Proxy()
        proxy.proxy_type = ProxyType.DIRECT
        if 'http' in self.proxy:
            proxy.http_proxy = self.proxy['http']
        if 'https' in self.proxy:
            proxy.ssl_proxy = self.proxy['https']

        capa = self._build_capabilities()
        proxy.add_to_capabilities(capa)

        options = self._build_options()
        # TODO some browsers don't need headless
        # TODO handle different proxy setting?
        options.set_headless(self.HEADLESS)

        if self.DRIVER is webdriver.Firefox:
            if self.responses_dirname and not os.path.isdir(self.responses_dirname):
                os.makedirs(self.responses_dirname)

            options.profile = DirFirefoxProfile(self.responses_dirname)
            if self.responses_dirname:
                capa['profile'] = self.responses_dirname
            self.driver = self.DRIVER(options=options, capabilities=capa)
        elif self.DRIVER is webdriver.Chrome:
            self.driver = self.DRIVER(options=options, desired_capabilities=capa)
        elif self.DRIVER is webdriver.PhantomJS:
            if self.responses_dirname:
                if not os.path.isdir(self.responses_dirname):
                    os.makedirs(self.responses_dirname)
                log_path = os.path.join(self.responses_dirname, 'selenium.log')
            else:
                log_path = NamedTemporaryFile(prefix='weboob_selenium_', suffix='.log', delete=False).name

            self.driver = self.DRIVER(desired_capabilities=capa, service_log_path=log_path)
        else:
            raise NotImplementedError()

        if self.WINDOW_SIZE:
            self.driver.set_window_size(*self.WINDOW_SIZE)