Пример #1
0
    def __init__(self,
                 browser_type="chrome",
                 driver_path=None,
                 *args,
                 **kwargs):
        """
        根据浏览器类型初始化浏览器
        :param browser_type: 浏览器类型,只可传入chrome或firefox
        :param driver_path:指定驱动存放的路径
        """
        # 检查browser_type值是否合法
        if browser_type not in ["chrome", "firefox"]:
            # 不合法报错
            logging.error("browser_type 输入值不为chrome,firefox")
            raise ValueError("browser_type 输入值不为chrome,firefox")

        self.__browser_type = browser_type

        # 根据browser_type值选择对应的驱动
        if self.__browser_type == "chrome":
            if driver_path:
                Chrome.__init__(self,
                                executable_path=driver_path,
                                *args,
                                **kwargs)
            else:
                Chrome.__init__(self, *args, **kwargs)
        elif self.__browser_type == "firefox":
            if driver_path:
                Firefox.__init__(self,
                                 executable_path=driver_path,
                                 *args,
                                 **kwargs)
            else:
                Firefox.__init__(self, *args, **kwargs)
Пример #2
0
 def __init__(self, edition_reviews=False):
     Chrome.__init__(self, desired_capabilities=self.OPTIONS)
     # Set page loading timeout to 30 seconds
     self.set_page_load_timeout(30)
     self.edition_reviews = edition_reviews
     # Initialize browsing counters
     self.rating = self.sort = self.fails = None
Пример #3
0
 def __init__(self, headless=True, options=[], path='myengine\chromedriver'):
     browser_options = ChromeOptions()
     for _ in options:
         browser_options.add_argument(_)
     browser_options.headless = headless
     browser_options.add_experimental_option('excludeSwitches', ['enable-logging'])
     Chrome.__init__(self, options=browser_options, executable_path=path)
     Browser.__init__(self)
Пример #4
0
 def __init__(self, params):
     """
     Instantiates Scraper object.
     @param params  (dict) : dictionary (JSON) object for Config
     """
     Chrome.__init__(self, ChromeDriverManager().install())
     Config.__init__(self, **params)
     # Create timestamp
     self.timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
Пример #5
0
 def __init__(self, gym, login, password):
     Chrome.__init__(self, self.executable_path, options=self.options)
     Chrome.implicitly_wait(self, self.time_to_wait)
     Chrome.get(self, self.ff_website)
     Chrome.find_element_by_css_selector(
         self, self.gym_selector).click()  # Expand gym location dropdown
     Chrome.find_element_by_link_text(self, gym).click()  # Choose gym
     Chrome.find_element_by_id(self, 'requiredtxtUserName').send_keys(login)
     Chrome.find_element_by_id(self,
                               'requiredtxtPassword').send_keys(password)
     Chrome.find_element_by_id(self, 'btnLogin').click()  # Login
Пример #6
0
 def __init__(self, b360bin=None, executable_path="chromedriver", port=0,
              chrome_options=None, service_args=None,
              desired_capabilities=None, service_log_path=None):
     if b360bin:
         self.bin = b360bin
     else:
         self.bin = r'%s\360Chrome\Chrome\Application\360chrome.exe' % os.getenv('LOCALAPPDATA')  ##你也可以读注册表来获取360的安装位置
     chrome_options = Options()
     chrome_options.binary_location = self.bin
     ChromeWebdriver.__init__(self, executable_path, port,
                 chrome_options, service_args,
                 desired_capabilities, service_log_path)
Пример #7
0
    def __init__(self,
                 as_user=False,
                 profile=None,
                 executable_path="/usr/bin/chromedriver",
                 downloads_folder=None,
                 options=None):
        if not options:
            options = Profile_Options(as_user=as_user,
                                      profile=profile,
                                      downloads_folder=downloads_folder)

        Browser_Webdriver.__init__(self,
                                   executable_path=executable_path,
                                   options=options)
Пример #8
0
 def __init__(self,
              live_server_url,
              executable_path="chromedriver",
              port=0,
              options=None,
              service_args=None,
              desired_capabilities=None,
              service_log_path=None,
              chrome_options=None,
              keep_alive=True):
     Chrome.__init__(self, executable_path, port, options, service_args,
                     desired_capabilities, service_log_path, chrome_options,
                     keep_alive)
     self.live_server_url = live_server_url
Пример #9
0
    def __init__(self):
        options = Options()
        options.add_argument('--no-sandbox')                        # 解决 DevToolsActivePort 文件不存在的报错
        options.add_argument('window-size=1920x3000')               # 指定浏览器分辨率
        options.add_argument('--disable-gpu')                       # 谷歌文档提到需要加上这个属性来规避bug
        options.add_argument('--hide-scrollbars')                   # 隐藏滚动条, 应对一些特殊页面
        # options.add_argument('blink-settings=imagesEnabled=false')  # 不加载图片, 提升速度
        options.add_argument('--headless')                          # 浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败
        # options.add_argument("user-data-dir=" + USER_DIR)            # 使用当前 chrome 的用户目录数据(需要关闭正在运行的 chrome)
        Chrome.__init__(self, executable_path='./chromedriver.exe', options=options)

        self.__path_save_images = './images/'
        self.__scrollTop = 0
        self.__input_express_num = None
        self.__button_search_express = None
 def __init__(self, gym):
     Chrome.__init__(self, self.executable_path) 
     Chrome.implicitly_wait(self, self.time_to_wait) 
     
     if gym == 'ccf':
         Chrome.get(self, self.ccf_website) 
     elif gym == 'ccsh':
         Chrome.get(self, self.ccsh_website) 
     else:
         Chrome.get(self, self.ccn_website)
     
     Chrome.maximize_window(self) 
     Chrome.find_element_by_xpath(self, '//*[@id="profile-link-div"]/div/a').click() 
     login_modal = Chrome.find_element_by_id(self, 'rgp00-embedded-modal-frame')
     self.switch_to.frame(login_modal)
     Chrome.find_element_by_id(self, 'inputEmail').send_keys(cc_login['login']) 
     Chrome.find_element_by_id(self, 'inputPassword').send_keys(cc_login['password'])
     Chrome.find_element_by_xpath(self, '/html/body/div[1]/div/div/form/div[1]/label/input').click()
     Chrome.find_element_by_xpath(self, '/html/body/div[1]/div/div/form/a[2]').click() # Click login
     Chrome.find_element_by_xpath(self, '/html/body/div[1]/div/div/div[1]/a').click() # Click done and exit
Пример #11
0
 def __init__(self):
     Chrome.__init__(self, desired_capabilities=self.OPTIONS)
     self.set_page_load_timeout(30)
     self.fails = 0
Пример #12
0
 def __init__(self, **kwargs):
     Chrome.__init__(self, **kwargs)
Пример #13
0
 def __init__(self):
     Chrome.__init__(self, desired_capabilities=self.options)
     # Set page loading timeout to 30 seconds
     self.set_page_load_timeout(8)
     self.fails = 0