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


Python Options.add方法代码示例

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


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

示例1: Sel_session

# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add [as 别名]
class Sel_session(object):
    def __init__(self, url='http://www.fsf.org/', driver = 'C:\\Program Files\\Mozilla Firefox\\firefox.exe',**kwargs):
        self.url = url
        #self.args = args
        self.binarypath = FirefoxBinary(driver)
        self.opts = Options()
        self.timeout = False
        if kwargs is not None:
            if kwargs.get('headless','') and kwargs['headless']: self.opts.add('--headless')
        self.driver = webdriver.Firefox(firefox_binary=self.binarypath, firefox_options=self.opts)
        #if true timeout enables the load_cutoff method in go_to
        


    def start(self):
        self.driver.get(self.url)
        return self.driver
    def go_to(self,x, **kwargs):
        self.driver.get(x)
        if self.timeout:
            self.load_cutoff(kwargs.get("timeout", 10))
    def go_to_TO(self, x, **kwargs):
        self.driver.get(x)
        try:
            WebDriverWait(self.driver, 10).until(readyCall())
        except TypeError as TE:
            print("TYPE ERROR")
            return
        except:
            raise(CustomTimeoutException("Timed out"))

    def js(self, x):
        return self.driver.execute_script(x)
    def close(self):
        return self.driver.quit()
    def is_enabled(self, prod_id):
        #checks to see if the element is DISABLED
        result = self.js("return 'disabled' in document.getElementById(\'{0}\').attributes".format(prod_id))
        if result:
            #if disabled is listed among the element's attributes returns False
            return False
        else:
            return True
    def w_load(self, T_O = 30):
        #waits for page to finish loading
        count = 0
        while True:
            if self.driver.execute_script('return document.readyState') != "complete" and count <= T_O:
                count += 1
                time.sleep(1)
            elif count > T_O:
                break #should probably do something else

            else:
                break
    def ready(self):
        if self.driver.execute_script('return document.readyState') == "complete":
            return True
        else:
            return False

    def load_cutoff(self, timeout = 10):

        start = time.time()
        while (time.time() - start) <= timeout and self.driver.execute_script('return document.readyState') != "complete":
            print("Wait time: {0}".format(time.time() - start))
        if (time.time() - start) > timeout and self.driver.execute_script('return document.readyState') != "complete":
            raise CustomTimeoutException("Timed out")





    def source(self):
        return bs(self.driver.page_source,'lxml')

    def element_check(self, element):
        try:
            self.driver.find_element_by_id(element)
        except:
            return False
        else:
            return True
    def export_cookies(self):
        return self.driver.get_cookies()
开发者ID:awaddell77,项目名称:Scrapers,代码行数:87,代码来源:Sel_session.py


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