python类FirefoxProfile()的实例源码

pantea.py 文件源码 项目:pantea 作者: nim4 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def browse(url, cookie, ua):
    domain = ".".join(url.split("/")[2].split(".")[-2:])
    cookies = cookie_dict(cookie, domain)
    profile = webdriver.FirefoxProfile()
    profile.set_preference("general.useragent.override", ua)
    browser = webdriver.Firefox(profile)
    browser.get(url)
    browser.delete_all_cookies()
    for c in cookies:
        try:
            browser.add_cookie(c)
        except:
            pass
    browser.get(url)
_browsermanagement.py 文件源码 项目:robotframework-weblibrary 作者: Netease-AutoTest 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def _make_ff(self , remote , desired_capabilites , profile_dir):

        if not profile_dir: profile_dir = FIREFOX_PROFILE_DIR
        profile = webdriver.FirefoxProfile(profile_dir)
        if remote:
            browser = self._create_remote_web_driver(webdriver.DesiredCapabilities.FIREFOX  ,
                        remote , desired_capabilites , profile)
        else:
            browser = webdriver.Firefox(firefox_profile=profile)
        return browser
WebDriverUtil.py 文件源码 项目:webnuke 作者: bugbound 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def getWebDriverProfile(self):
        profile = webdriver.FirefoxProfile()
        #profile.set_preference("browser.cache.disk.enable", False)
        #profile.set_preference("browser.cache.memory.enable", False)
        #profile.set_preference("browser.cache.offline.enable", False)
        #profile.set_preference("network.http.use-cache", False)
        return profile
mobidriver.py 文件源码 项目:Mobilenium 作者: rafpyprog 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def add_proxy_to_profile(self, profile):
        if profile is None:
            self.profile = webdriver.FirefoxProfile()
            self.profile.set_proxy(self.proxy.selenium_proxy())
        else:
            self.profile = profile
            self.profile.set_proxy(self.proxy.selenium_proxy())
insecam.py 文件源码 项目:CAM2RetrieveData 作者: PurdueCAM2Project 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self):
        # store the url of homepage, traffic page, the country code, and the state code
        self.home_url = "http://www.insecam.org"
        self.traffic_url = "http://www.insecam.org/"

        # open the file to store the list and write the format of the list at the first line
        self.us = open('list_insecam_US.txt', 'w')
        self.us.write("city#country#state#snapshot_url#latitude#longitude" + "\n")

        self.ot = open('list_insecam_Other.txt', 'w')
        self.ot.write("city#country#snapshot_url#latitude#longitude" + "\n")

        # open the web-driver
        firefox_profile = webdriver.FirefoxProfile()
        firefox_profile.set_preference("browser.download.folderList", 2)
        firefox_profile.set_preference("javascript.enabled", False)

        self.driver = webdriver.Firefox(firefox_profile=firefox_profile)

        # list of categories that it will parse and list of image URLs that should not be parsed
        self.categories = ['City', 'Village', 'River' 'Square', 'Construction', 'Bridge', 'Nature', 'Mountain', 'Traffic', 'Street', 'Road', 'Architecture', 'Port', 'Beach']
        self.invalid = ['http://admin:@50.30.102.221:85/videostream.cgi',
                        'http://198.1.4.43:80/mjpg/video.mjpg?COUNTER',
                        'http://97.76.101.212:80/mjpg/video.mjpg?COUNTER',
                        'http://24.222.206.98:1024/img/video.mjpeg?COUNTER',
                        'http://71.43.210.90:80/SnapshotJPEG?Resolution=640x480&Quality=Clarity&1467044876',
                        'http://61.149.161.158:82/mjpg/video.mjpg?COUNTER',
                        "http://213.126.67.202:1024/oneshotimage1",
                        "http://71.90.110.144:8080/img/video.mjpeg?COUNTER",
                        "http://95.63.206.142:80/mjpg/video.mjpg?COUNTER",
                        "http://201.229.94.197:80/mjpg/video.mjpg?COUNTER"
                       ]
tests_bing_automater.py 文件源码 项目:BingAutomater 作者: sohail288 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_make_profile(self):
        profile = BingAutomater.make_profile()

        profile_type = type(profile)
        is_it_equal = profile_type == type(webdriver.FirefoxProfile())

        javascript_enabled = profile.default_preferences.get('javascript.enabled', None)
        max_script_run_time = profile.default_preferences.get('dom.max_script_run_time', None) 


        self.assertTrue(is_it_equal)
        self.assertFalse(javascript_enabled)
        self.assertEqual(max_script_run_time, 0)
bing_automater.py 文件源码 项目:BingAutomater 作者: sohail288 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def initialize_driver(url, userInfo, passInfo, prof = None ):
    """ signs into outlook and returns driver
        Optional argument of prof can change UA of driver
    """

    default_prof = webdriver.FirefoxProfile()
    default_prof.set_preference("dom.max_chrome_script_run_time", 0)
    default_prof.set_preference("dom.max_script_run_time", 0)
    default_prof.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
                                      'false')
    default_prof.set_preference("javascript.enabled", False);

    profile_to_use = prof if prof is not None else default_prof
    profile_to_use.add_extension(extension=adblock_xpi)


    driver = webdriver.Firefox(profile_to_use)

    time.sleep(10)
    driver.get("http://www.outlook.com")

    try:
        user = driver.find_element_by_name("loginfmt")
        pass_ = driver.find_element_by_name("passwd")
        user.send_keys(userInfo)
        pass_.send_keys(passInfo)
        time.sleep(5)
        user.submit()
    except (NoSuchElementException, TimeoutException) as err:
        print("Couldn't initialize browser: %s", err)

    time.sleep(10)
    return driver
bing_automater.py 文件源码 项目:BingAutomater 作者: sohail288 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def setup_mobile_profile():
    """ Sets up a profile to use with driver, returns profile"""
    prof = webdriver.FirefoxProfile()
    ua_string = MOBILE_UA
    prof.set_preference("general.useragent.override", ua_string)
    prof.set_preference("dom.max_chrome_script_run_time", 0)
    prof.set_preference("dom.max_script_run_time", 0)
    prof.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
                                      'false')
    return prof
BingAutomater.py 文件源码 项目:BingAutomater 作者: sohail288 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def make_profile():
    """ Set up a profile and return it """

    profile = webdriver.FirefoxProfile()
    profile.set_preference("dom.max_chrome_script_run_time", 0)
    profile.set_preference("dom.max_script_run_time", 0)
    profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
                                      'false')
    profile.set_preference("javascript.enabled", False)


    #profile_to_use.add_extension(extension=adblock_xpi)
    return profile
torutils_pj.py 文件源码 项目:webfp-crawler-phantomjs 作者: pankajb64 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def init_tbb_profile(self, version):
        profile_directory = cm.get_tbb_profile_path(version)
        self.prof_dir_path = clone_dir_with_timestap(profile_directory)
        if self.capture_screen and self.page_url:
            self.add_canvas_permission()
        try:
            tbb_profile = webdriver.FirefoxProfile(self.prof_dir_path)
        except Exception:
            wl_log.error("Error creating the TB profile", exc_info=True)
        else:
            return tbb_profile
torutils.py 文件源码 项目:webfp-crawler-phantomjs 作者: pankajb64 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def init_tbb_profile(self, version):
        profile_directory = cm.get_tbb_profile_path(version)
        self.prof_dir_path = clone_dir_with_timestap(profile_directory)
        if self.capture_screen and self.page_url:
            self.add_canvas_permission()
        try:
            tbb_profile = webdriver.FirefoxProfile(self.prof_dir_path)
        except Exception:
            wl_log.error("Error creating the TB profile", exc_info=True)
        else:
            return tbb_profile
plugin.py 文件源码 项目:phat 作者: danielfranca 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def get_firefox_driver(path = None, selenium_grid_hub = None, no_proxy=False):

    if selenium_grid_hub:
        desired_capabilities={
            "browserName": "firefox",
            "javascriptEnabled": True,
            "proxy": {
                "proxyType": "direct" if no_proxy else "system"
            }
        }

        profile = webdriver.FirefoxProfile()
        profile.set_preference("network.http.phishy-userpass-length", 255);

        return webdriver.Remote(command_executor=selenium_grid_hub, desired_capabilities=desired_capabilities, browser_profile=profile)
    else:
        binary = None
        if path:
            binary = FirefoxBinary(path) #, log_file=open("/tmp/bat_firefox", 'a'))
        profile = webdriver.FirefoxProfile()
        profile.set_preference("network.http.phishy-userpass-length", 255);
        profile.set_preference("network.proxy.type", 0)
        capabilities = None
        if USE_MARIONETTE:
            # tell webdriver to use Marionette instead of plain Firefox
            capabilities = DesiredCapabilities.FIREFOX
            capabilities["marionette"] = True
        return webdriver.Firefox(firefox_profile=profile, firefox_binary=binary, capabilities=capabilities)
fbot.py 文件源码 项目:fbot 作者: eracle 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def login(email, password):
    """
    Performs a Login to the Facebook platform.
    :param email: The used email account.
    :param password: Its password
    :return: Returns the logged Selenium web driver and the user name string.
    """
    logger.info('Init Firefox Browser')
    profile = webdriver.FirefoxProfile()
    profile.set_preference('dom.disable_beforeunload', True)
    driver = webdriver.Firefox(profile)

    driver.get('https://www.facebook.com')

    logger.info('Log in - Searching for the email input')
    get_by_xpath(driver, '//input[@id="email"]').send_keys(email)

    logger.info('Log in - Searching for the password input')
    get_by_xpath(driver, '//input[@id="pass"]').send_keys(password)

    logger.info('Log in - Searching for the submit button')
    get_by_xpath(driver, '//input[@type="submit"]').click()

    logger.info('Log in - get the user name')
    user_name = get_by_xpath(driver, '//a[@class="fbxWelcomeBoxName"]').text

    logger.info('Log in - Saving the username, which is: %s' % user_name)
    return driver, user_name
archivematicaselenium.py 文件源码 项目:archivematica-acceptance-tests 作者: artefactual-labs 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_driver(self):
        if self.driver_name == 'PhantomJS':
            # These capabilities were part of a failed attempt to make the
            # PhantomJS driver work.
            cap = webdriver.DesiredCapabilities.PHANTOMJS
            cap["phantomjs.page.settings.resourceTimeout"] = 20000
            cap["phantomjs.page.settings.userAgent"] = \
                ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5)'
                 ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116'
                 ' Safari/537.36')
            return webdriver.PhantomJS(desired_capabilities=cap)
        elif self.driver_name == 'Chrome':
            driver = webdriver.Chrome()
            driver.set_window_size(1700, 900)
        elif self.driver_name == 'Chrome-Hub':
            capabilities = DesiredCapabilities.CHROME.copy()
            capabilities["chrome.switches"] = [
                "--start-maximized",
                '--ignore-certificate-errors',
                '--test-type']
            driver = webdriver.Remote(
                command_executor=os.environ.get('HUB_ADDRESS'),
                desired_capabilities=capabilities)
            driver.set_window_size(1200, 900)
        elif self.driver_name == 'Firefox':
            fp = webdriver.FirefoxProfile()
            fp.set_preference("dom.max_chrome_script_run_time", 0)
            fp.set_preference("dom.max_script_run_time", 0)
            driver = webdriver.Firefox(firefox_profile=fp)
        elif self.driver_name == 'Firefox-Hub':
            driver = webdriver.Remote(
                command_executor=os.environ.get('HUB_ADDRESS'),
                desired_capabilities=DesiredCapabilities.FIREFOX)
        else:
            driver = getattr(webdriver, self.driver_name)()
        driver.set_script_timeout(10)
        self.all_drivers.append(driver)
        return driver
optimisedSpider.py 文件源码 项目:linkedinSpider 作者: pediredla 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def FirefoxProfileSettings():
    profile = webdriver.FirefoxProfile()
    profile.set_preference('network.proxy.type', 1)
    profile.set_preference('network.proxy.socks', '127.0.0.1')
    profile.set_preference('network.proxy.socks_port', 9050)

    return profile
spider.py 文件源码 项目:linkedinSpider 作者: pediredla 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def FirefoxProfileSettings():
    profile=webdriver.FirefoxProfile()
    profile.set_preference('network.proxy.type', 1)
    profile.set_preference('network.proxy.socks', '127.0.0.1')
    profile.set_preference('network.proxy.socks_port', 9050)

    return profile
crawler.py 文件源码 项目:poll-analysis 作者: minwooat 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def init_driver():
    profile = webdriver.FirefoxProfile('/Users/MinWooKim/Library/Application Support/Firefox/Profiles/axkhqz5b.default')
    profile.set_preference('browser.download.folderList', 2)
    profile.set_preference('browser.download.dir', '~/Desktop/polls')
    driver = webdriver.Firefox(profile)
    driver.wait = WebDriverWait(driver, 2)
    return driver
selenium.py 文件源码 项目:SerpScrap 作者: ecoron 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _get_Firefox(self):
        try:
            if self.proxy:
                profile = webdriver.FirefoxProfile()
                profile.set_preference(
                    "network.proxy.type",
                    1
                )  # this means that the proxy is user set
                if self.proxy.proto.lower().startswith('socks'):
                    profile.set_preference(
                        "network.proxy.socks",
                        self.proxy.host
                    )
                    profile.set_preference(
                        "network.proxy.socks_port",
                        self.proxy.port
                    )
                    profile.set_preference(
                        "network.proxy.socks_version",
                        5 if self.proxy.proto[-1] == '5' else 4
                    )
                    profile.update_preferences()
                elif self.proxy.proto == 'http':
                    profile.set_preference(
                        "network.proxy.http",
                        self.proxy.host
                    )
                    profile.set_preference(
                        "network.proxy.http_port",
                        self.proxy.port
                    )
                else:
                    raise ValueError('Invalid protocol given in proxyfile.')
                profile.update_preferences()
                self.webdriver = webdriver.Firefox(firefox_profile=profile)
            else:
                self.webdriver = webdriver.Firefox()
            return True
        except WebDriverException as e:
            # no available webdriver instance.
            logger.error(e)
        return False
collector.py 文件源码 项目:betaPika 作者: alchemistake 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def __init__(self, running, browser, send_mails, format_list):

        super(CollectorProcess, self).__init__()

        self.format_list = format_list
        self.running = running
        self.send_mails = send_mails

        # Setting "Downloads" path up
        self.download_path = os.path.abspath(os.path.join(os.curdir, "RAW-collection"))

        if not os.path.exists(self.download_path):
            os.mkdir(self.download_path)

        # Selecting browser
        self.driver = None
        if browser == "chrome":
            chrome_options = webdriver.ChromeOptions()
            preferences = {"download.default_directory": self.download_path}
            chrome_options.add_experimental_option("prefs", preferences)

            # Loading the page
            self.driver = webdriver.Chrome(chrome_options=chrome_options)
        elif browser == "firefox":
            profile = webdriver.FirefoxProfile()

            profile.set_preference("browser.download.folderList", 2)
            profile.set_preference("browser.download.dir", self.download_path)
            profile.set_preference("browser.download.manager.alertOnEXEOpen", False)
            profile.set_preference("browser.helperApps.neverAsk.saveToDisk",
                                   "application/msword, application/csv, application/ris, text/csv, image/png, " +
                                   "application/pdf, text/html, text/plain, application/zip, application/x-zip, " +
                                   "application/x-zip-compressed, application/download, application/octet-stream")
            profile.set_preference("browser.download.manager.showWhenStarting", False)
            profile.set_preference("browser.download.manager.focusWhenStarting", False)
            profile.set_preference("browser.download.useDownloadDir", True)
            profile.set_preference("browser.helperApps.alwaysAsk.force", False)
            profile.set_preference("browser.download.manager.alertOnEXEOpen", False)
            profile.set_preference("browser.download.manager.closeWhenDone", True)
            profile.set_preference("browser.download.manager.showAlertOnComplete", False)
            profile.set_preference("browser.download.manager.useWindow", False)
            profile.set_preference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", False)
            profile.set_preference("pdfjs.disabled", True)

            self.driver = webdriver.Firefox(firefox_profile=profile)
        else:
            raise ValueError('Browser can only be either "chrome" or "firefox"')

        self.currently_open_battles = set()
        self.leave_que = []

        self.format_index = -1
        self.format_length = len(self.format_list)
Connect.py 文件源码 项目:myautotest 作者: auuppp 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def start(self,testhost='',browsertype='',implicity_wait_timeout=IMPLICITY_WAIT_TIMEOUT):
        '''
        To open a browser
        '''
        browser = None
        # lists={
        #      'http://192.168.195.2:8888/wd/hub':'firefox',
        #      #'http://172.16.142.241:7777/wd/hub':'chrome',
        #      }
        # for host,bsr in lists.items():
        #     print host,bsr
        if testhost=='':
            if browsertype.startswith('Chrome'):
                chromedriver = os.path.join(os.environ["AUTODIR"], "webdriver", "chromedriver.exe")
                #Cloud_DebugLog.debug_print("To print the chromedirver path: " + chromedriver)
                chromedriver = os.path.abspath(chromedriver)
                os.environ["webdriver.chrome.driver"] = chromedriver
                chrome_options = Options()
                chrome_options.add_argument("--ignore-certificate-errors")
                chrome_options.add_argument("--disable-popup-blocking")
                options = webdriver.ChromeOptions()
                # set some options
                #driver = webdriver.Remote(desired_capabilities=options.to_capabilities())
                options.add_argument("--always-authorize-plugins")            
                #for opt in options.arguments():
                #    Cloud_DebugLog.info_print("option : " + opt)

                browser_chrome = webdriver.Chrome(chromedriver, chrome_options=options)            
                browser = browser_chrome
            else:
                fp = webdriver.FirefoxProfile()
                fp.set_preference("browser.download.folderList",2)
                fp.set_preference("browser.download.manager.showWhenStarting",False)
                fp.set_preference("browser.download.dir","d:\\test") 
                fp.set_preference("browser.helperApps.neverAsk.saveToDisk","application/binary")
                #fp.set_preference("browser.helperApps.alwaysAsk.force", False);
                browser = webdriver.Firefox(firefox_profile=fp)

            if not browser:
                raise(TestError("No browser opened"))
        else:
            browser = Remote(
                          command_executor=testhost+"/wd/hub",
                          desired_capabilities={'platform':'ANY',
                                                'browserName':browsertype,
                                                'version': '', 
                                                'javascriptEnabled':True
                                            }
                                )
            #driver = Remote(command_executor='http://127.0.0.1:4444/wd/hub',desired_capabilities={'platform': 'ANY','browserName':'chrome',  'version': '', 'javascriptEnabled':True})


        browser.implicitly_wait(implicity_wait_timeout)
        browser.maximize_window()
        browser.get(self.url)

        return browser


问题


面经


文章

微信
公众号

扫码关注公众号