当前位置: 首页>>代码示例>>Python>>正文


Python options.Options方法代码示例

本文整理汇总了Python中selenium.webdriver.chrome.options.Options方法的典型用法代码示例。如果您正苦于以下问题:Python options.Options方法的具体用法?Python options.Options怎么用?Python options.Options使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在selenium.webdriver.chrome.options的用法示例。


在下文中一共展示了options.Options方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from selenium.webdriver.chrome import options [as 别名]
# 或者: from selenium.webdriver.chrome.options import Options [as 别名]
def __init__(self, use_Dingtalk=False):
        chrome_options = Options()
        self.__exit_flag = threading.Event()
        self.__exit_flag.clear()
        self.use_Dingtalk = use_Dingtalk
        if config['mute']:
            chrome_options.add_argument('--mute-audio')  # 关闭声音

        if os.path.exists('driver/chrome.exe'):
            chrome_options.binary_location = 'driver/chrome.exe'
        # chrome_options.add_argument('--no-sandbox')#解决DevToolsActivePort文件不存在的报错
        # chrome_options.add_argument('window-size=800x600') #指定浏览器分辨率
        # chrome_options.add_argument('--disable-gpu') #谷歌文档提到需要加上这个属性来规避bug
        # chrome_options.add_argument('--hide-scrollbars') #隐藏滚动条, 应对一些特殊页面
        # chrome_options.add_argument('blink-settings=imagesEnabled=false') #不加载图片, 提升速度
        if config['background_process'] and self.use_Dingtalk:
            chrome_options.add_argument('--headless')  # 浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败
        self.driver = webdriver.Chrome('driver/chromedriver.exe', options=chrome_options)
        LOGGER.setLevel(logging.CRITICAL) 
开发者ID:zodiac182,项目名称:autoxuexi,代码行数:21,代码来源:xuexi.py

示例2: __init__

# 需要导入模块: from selenium.webdriver.chrome import options [as 别名]
# 或者: from selenium.webdriver.chrome.options import Options [as 别名]
def __init__(self):
        self.browse = None
        self.source_playlist = None
        self.target_playlist_tag = None
        self.success_list = list()
        self.failed_list = list()
        os.environ["webdriver.chrome.driver"] = chrome_driver_path
        os.environ["webdriver.phantomjs.driver"] = phantomjs_driver_path
        # chromedriver = chrome_driver_path
        phantomjs_driver = phantomjs_driver_path

        opts = Options()
        opts.add_argument("user-agent={}".format(headers["User-Agent"]))
        # browser = webdriver.Chrome(chromedriver)
        browser = webdriver.PhantomJS(phantomjs_driver)
        self.browser = browser
        self.wait = ui.WebDriverWait(self.browser, 5)
        self.config = Config() 
开发者ID:Denon,项目名称:syncPlaylist,代码行数:20,代码来源:base.py

示例3: driver

# 需要导入模块: from selenium.webdriver.chrome import options [as 别名]
# 或者: from selenium.webdriver.chrome.options import Options [as 别名]
def driver():
    options = Options()
    options.headless = True
    arguments = ['--incognito', '--private']
    if platform.system() == 'Darwin':
        chrome_path = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
        data_dir = os.path.join(tempfile.gettempdir(), 'local-probe-chrome-data')
        options.binary_location = chrome_path
    else:
        arguments.extend(['--no-sandbox', '--disable-dev-shm-usage'])
        data_dir = '/home/circleci/project/data'
    arguments.append('--user-data-dir={}'.format(data_dir))
    for argument in arguments:
        options.add_argument(argument)
    result = webdriver.Chrome(options=options)
    result.set_window_size(1600, 1000)
    yield result
    result.close() 
开发者ID:dankilman,项目名称:awe,代码行数:20,代码来源:infra.py

示例4: _driver

# 需要导入模块: from selenium.webdriver.chrome import options [as 别名]
# 或者: from selenium.webdriver.chrome.options import Options [as 别名]
def _driver():
    options = Options()
    options.headless = True
    arguments = ['--incognito', '--private']
    chrome_path = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
    data_dir = os.path.join(tempfile.gettempdir(), 'local-probe-chrome-data')
    options.binary_location = chrome_path
    arguments.append('--user-data-dir={}'.format(data_dir))
    for argument in arguments:
        options.add_argument(argument)
    result = webdriver.Chrome(options=options)
    try:
        result.set_window_size(1600, 1000)
        yield result
    finally:
        result.close() 
开发者ID:dankilman,项目名称:awe,代码行数:18,代码来源:export_examples.py

示例5: start_session

# 需要导入模块: from selenium.webdriver.chrome import options [as 别名]
# 或者: from selenium.webdriver.chrome.options import Options [as 别名]
def start_session(username, password):
    print("Opening Browser...")
    wd_options = Options()
    wd_options.add_argument("--disable-notifications")
    wd_options.add_argument("--disable-infobars")
    wd_options.add_argument("--mute-audio")
    wd_options.add_argument("--start-maximized")
    driver = webdriver.Chrome(chrome_options=wd_options)

    #Login
    driver.get("https://www.facebook.com/")
    print("Logging In...")
    email_id = driver.find_element_by_id("email")
    pass_id = driver.find_element_by_id("pass")
    email_id.send_keys(username)
    pass_id.send_keys(password)
    driver.find_element_by_id("loginbutton").click()

    return driver 
开发者ID:jcontini,项目名称:facebook-photos-download,代码行数:21,代码来源:get-tagged-photos.py

示例6: chrome_driver

# 需要导入模块: from selenium.webdriver.chrome import options [as 别名]
# 或者: from selenium.webdriver.chrome.options import Options [as 别名]
def chrome_driver():
    chrome_driver_path = cb.utils.get_chromedriver_path()
    chrome_driver_exe = os.path.join(
        chrome_driver_path, cb.utils.get_chromedriver_filename())
    if os.name != 'nt' and 'microsoft' in platform.uname().version.lower():
        chrome_driver_exe += '.exe'
    if not os.path.exists(chrome_driver_exe):
        msg = 'invalid driver module at \'{}\' error'.format(chrome_driver_exe)
        raise ValueError(msg)

    options = Options()
    options.add_argument('--headless')
    options.add_argument('--window-size=1200,1024')
    driver = webdriver.Chrome(
        chrome_options=options, executable_path=chrome_driver_exe)

    try:
        yield driver
    finally:
        driver.quit() 
开发者ID:chainer,项目名称:chainerui,代码行数:22,代码来源:cap_train.py

示例7: takeScreeshot

# 需要导入模块: from selenium.webdriver.chrome import options [as 别名]
# 或者: from selenium.webdriver.chrome.options import Options [as 别名]
def takeScreeshot(url):
    if len(url) == 0:
        return False
    else:
        u = urlParser(url.strip())
        if u:
            if not os.path.exists(OUTPUT):
                os.makedirs(OUTPUT)
            
            chrome_options = Options()
            chrome_options.add_argument("--headless") 
            driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"), chrome_options=chrome_options)
            driver.set_window_size(1280, 1024) 
            driver.get(u)
            driver.save_screenshot(os.getcwd() + '/' +OUTPUT + '/screenshot-' + urlparse(url).path + '.png')  
            return True
        else:
            return False 
开发者ID:mdhama,项目名称:lazyshot,代码行数:20,代码来源:lazyshot.py

示例8: __init__

# 需要导入模块: from selenium.webdriver.chrome import options [as 别名]
# 或者: from selenium.webdriver.chrome.options import Options [as 别名]
def __init__(self, wait, screenshot=None, session=None):
        chrome_options = Options()
        if session:
            chrome_options.add_argument("--user-data-dir={}".format(session))
            self.browser = webdriver.Chrome(options=chrome_options)  # we are using chrome as our webbrowser
        else:
            self.browser = webdriver.Chrome()
        self.browser.get("https://web.whatsapp.com/")
        # emoji.json is a json file which contains all the emojis
        with open("emoji.json") as emojies:
            self.emoji = json.load(emojies)  # This will load the emojies present in the json file into the dict
        WebDriverWait(self.browser,wait).until(EC.presence_of_element_located(
            (By.CSS_SELECTOR, '._3FRCZ')))
        if screenshot is not None:
            self.browser.save_screenshot(screenshot)  # This will save the screenshot to the specified file location

    # This method is used to send the message to the individual person or a group
    # will return true if the message has been sent, false else 
开发者ID:VISWESWARAN1998,项目名称:Simple-Yet-Hackable-WhatsApp-api,代码行数:20,代码来源:whatsapp.py

示例9: __init__

# 需要导入模块: from selenium.webdriver.chrome import options [as 别名]
# 或者: from selenium.webdriver.chrome.options import Options [as 别名]
def __init__(self, proxy=None):
        chrome_options = Options()
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--disable-gpu')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--disable-dev-shm-usage')
        chrome_options.add_argument('--ignore-certificate-errors')
        chrome_options.add_argument('--ignore-ssl-errors')
        prefs = {"profile.managed_default_content_settings.images": 2}
        chrome_options.add_experimental_option("prefs", prefs)
        if proxy:
            proxy_address = proxy['https']
            chrome_options.add_argument('--proxy-server=%s' % proxy_address)
            logging.info('Chrome using proxy: %s', proxy['https'])
        # 设置等待策略为不等待完全加载
        caps = DesiredCapabilities().CHROME
        caps["pageLoadStrategy"] = "none"
        self.chrome = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=caps)
        # jd sometimes load google pic takes much time
        self.chrome.set_page_load_timeout(30)
        # set timeout for script
        self.chrome.set_script_timeout(30) 
开发者ID:qqxx6661,项目名称:Price-monitor,代码行数:24,代码来源:crawler_selenium.py

示例10: get_driver

# 需要导入模块: from selenium.webdriver.chrome import options [as 别名]
# 或者: from selenium.webdriver.chrome.options import Options [as 别名]
def get_driver(self, url, execute_path=None, is_headless=True):
        driver = None
        try:
            chrome_options = Options()
            if is_headless:
                chrome_options.add_argument('--headless')
            chrome_options.add_argument('--disable-gpu')
            if execute_path is None:
                driver = webdriver.Chrome(chrome_options=chrome_options)
            else:
                driver = webdriver.Chrome(executable_path=execute_path, chrome_options=chrome_options)
            driver.get(url)
            return driver.page_source
        except Exception as e:
            raise IOError(e)
        finally:
            if driver is not None:
                driver.quit() 
开发者ID:GraySilver,项目名称:wencai,代码行数:20,代码来源:session.py

示例11: getHeXinVByHttp

# 需要导入模块: from selenium.webdriver.chrome import options [as 别名]
# 或者: from selenium.webdriver.chrome.options import Options [as 别名]
def getHeXinVByHttp(self, source):
        driver = None
        try:
            chrome_options = Options()
            if self.is_headless:
                chrome_options.add_argument('--headless')
            chrome_options.add_argument('--disable-gpu')
            if self.execute_path is None:
                driver = webdriver.Chrome(chrome_options=chrome_options)
            else:
                driver = webdriver.Chrome(executable_path=self.execute_path, chrome_options=chrome_options)

            driver.get(WENCAI_LOGIN_URL[source])
            time.sleep(5)
            cookies = driver.get_cookies()
            v = ''
            for i in cookies:
                if 'name' in i.keys():
                    if i['name'] == 'v': v = i['value']
            return v
        except Exception as e:
            print(e)
        finally:
            if driver is not None:
                driver.quit() 
开发者ID:GraySilver,项目名称:wencai,代码行数:27,代码来源:cookies.py

示例12: setUpClass

# 需要导入模块: from selenium.webdriver.chrome import options [as 别名]
# 或者: from selenium.webdriver.chrome.options import Options [as 别名]
def setUpClass(cls):
        super(IntegrationTests, cls).setUpClass()

        options = Options()
        if 'DASH_TEST_CHROMEPATH' in os.environ:
            options.binary_location = os.environ['DASH_TEST_CHROMEPATH']

        cls.driver = webdriver.Chrome(chrome_options=options)

        root_static_dir = os.path.abspath(
            os.path.join(
                os.path.dirname(__file__),
                '..',
                'assets'
            )
        )

        if os.environ.get('PERCY_ENABLED', False):
            loader = percy.ResourceLoader(
                webdriver=cls.driver,
                base_url='/assets',
                root_dir=root_static_dir
            )
            cls.percy_runner = percy.Runner(loader=loader)
            cls.percy_runner.initialize_build() 
开发者ID:plotly,项目名称:dash-bio,代码行数:27,代码来源:IntegrationTests.py

示例13: get_driver

# 需要导入模块: from selenium.webdriver.chrome import options [as 别名]
# 或者: from selenium.webdriver.chrome.options import Options [as 别名]
def get_driver(self):

        cur_path_list = os.getcwd().split("/")[:-1]
        cur_path = "/".join(cur_path_list) + "/dependencies/chromedriver/chromedriver"

        if not os.path.exists(cur_path):
            self.dl_driver_mac()

        cur_path_list = os.getcwd().split("/")[:-1]
        cur_path = "/".join(cur_path_list) + "/config/"
        cmd = '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --user-data-' \
              'dir="{}" '.format(cur_path)
        subprocess.Popen(cmd, shell=True)

        chrome_options = Options()
        chrome_options.debugger_address = "127.0.0.1:9222"

        cur_path_list = os.getcwd().split("/")[:-1]
        cur_path = "/".join(cur_path_list) + "/dependencies/chromedriver/chromedriver"

        driver = webdriver.Chrome(cur_path, options=chrome_options)
        cmd = """ osascript -e 'tell application "System Events" to keystroke "h" using {command down}' """
        os.system(cmd)
        return driver 
开发者ID:edisonwong520,项目名称:jarvis,代码行数:26,代码来源:Chrome.py

示例14: setUp

# 需要导入模块: from selenium.webdriver.chrome import options [as 别名]
# 或者: from selenium.webdriver.chrome.options import Options [as 别名]
def setUp(self):
        set_up_data()

        # To run Chrome in CI environments.
        chrome_options = Options()
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--disable-dev-shm-usage')
        chrome_options.add_argument("window-size=1200x600")
        if (os.environ.get('SELENIUM_VISUAL', None) == '1'):
            self.browser = webdriver.Chrome()
            self.browser.set_window_size(1600, 900)
        else:
            self.browser = webdriver.Chrome(options = chrome_options)

        self.domain_home = 'http://localhost' + ':' + \
                self.live_server_url.split(':')[-1] 
开发者ID:dibs-devs,项目名称:chatter,代码行数:19,代码来源:test_chat_behavior.py

示例15: get_driver

# 需要导入模块: from selenium.webdriver.chrome import options [as 别名]
# 或者: from selenium.webdriver.chrome.options import Options [as 别名]
def get_driver():
    current_platform = platform.system()
    driver = None
    if current_platform == 'Darwin':
        from selenium import webdriver
        from selenium.webdriver.chrome.options import Options
        chrome_options = Options()
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--disable-gpu')
        driver = webdriver.Chrome('/Users/nolan/Documents/chromedriver', chrome_options=chrome_options)
        driver.set_page_load_timeout(60)
        time.sleep(0.5)
    if current_platform == 'Linux':
        from selenium import webdriver
        from selenium.webdriver.chrome.options import Options
        chrome_options = Options()
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--disable-gpu')
        driver = webdriver.Chrome(chrome_options=chrome_options)
        driver.set_page_load_timeout(60)
        time.sleep(0.5)
    return driver 
开发者ID:nolanzhao,项目名称:FutureNews,代码行数:24,代码来源:crawler.py


注:本文中的selenium.webdriver.chrome.options.Options方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。