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


Python webdriver.FirefoxProfile方法代码示例

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


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

示例1: test_webdriver2

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxProfile [as 别名]
def test_webdriver2(self):
        import time
        from selenium import webdriver

        # myProxy = "127.0.0.1:9150"
        myProxy = "192.168.103.1:1081"
        ip, port = myProxy.split(":")
        fp = webdriver.FirefoxProfile()
        fp.set_preference('network.proxy.type', 1)
        fp.set_preference('network.proxy.socks', ip)
        fp.set_preference('network.proxy.socks_port', int(port))
        driver = webdriver.Firefox(fp)
        url = 'https://api.ipify.org'
        # url = "http://data.eastmoney.com/hsgtcg/StockHdDetail.aspx?stock=600519&date=2018-06-12/"
        driver.get(url)
        # print(driver.find_element_by_tag_name('table').text)
        print(driver.find_element_by_tag_name('pre').text)
        driver.get('https://check.torproject.org/')
        time.sleep(3)
        driver.quit() 
开发者ID:pchaos,项目名称:wanggeService,代码行数:22,代码来源:test_get_proxy.py

示例2: __init__

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxProfile [as 别名]
def __init__(self, items):
        """Setup bot for Amazon URL."""
        self.amazon_url = "https://www.amazon.ca/"
        self.items = items

        self.profile = webdriver.FirefoxProfile()
        self.options = Options()
        #self.options.add_argument("--headless")
        self.driver = webdriver.Firefox(firefox_profile=self.profile,
                                        firefox_options=self.options)

        # Navigate to the Amazon URL.
        self.driver.get(self.amazon_url)

        # Obtain the source
        self.html = self.driver.page_source
        self.soup = BeautifulSoup(self.html, 'html.parser')
        self.html = self.soup.prettify('utf-8') 
开发者ID:vprusso,项目名称:youtube_tutorials,代码行数:20,代码来源:amazon_bot.py

示例3: getWebDriver

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxProfile [as 别名]
def getWebDriver():
    if not os.path.isfile(cfg['WEBDRIVER']['PATH']):
        print("{0} does not exist - install a webdriver".format(cfg['WEBDRIVER']['PATH']))
        sys.exit(-2)
    d = cfg['WEBDRIVER']['ENGINE']
    if d.lower() == 'firefox':
        os.environ["webdriver.firefox.driver"] = cfg['WEBDRIVER']['PATH']
        p = os.path.join(tempfile.gettempdir(), 'imageraider')
        if not os.path.isdir(p):
            os.makedirs(p)
        profile = webdriver.FirefoxProfile()
        profile.set_preference('browser.download.folderList', 2) # custom location
        profile.set_preference('browser.download.manager.showWhenStarting', False)
        profile.set_preference('browser.download.dir', p)
        profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'text/csv')
        profile.set_preference("browser.link.open_newwindow", 3)
        profile.set_preference("browser.link.open_newwindow.restriction", 2)
        return webdriver.Firefox(profile)
    else:
        os.environ["webdriver.chrome.driver"] = cfg['WEBDRIVER']['PATH']
        return webdriver.Chrome() 
开发者ID:ThoughtfulDev,项目名称:EagleEye,代码行数:23,代码来源:config.py

示例4: getWebdriver

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxProfile [as 别名]
def getWebdriver(self, driverType):
		if driverType == 'proxy':
			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", 9150 )
			profile.set_preference( "network.proxy.socks_remote_dns", True )
			profile.set_preference( "places.history.enabled", False )
			profile.set_preference( "privacy.clearOnShutdown.offlineApps", True )
			profile.set_preference( "privacy.clearOnShutdown.passwords", True )
			profile.set_preference( "privacy.clearOnShutdown.siteSettings", True )
			profile.set_preference( "privacy.sanitize.sanitizeOnShutdown", True )
			profile.set_preference( "signon.rememberSignons", False )
			profile.set_preference( "network.cookie.lifetimePolicy", 2 )
			profile.set_preference( "network.dns.disablePrefetch", True )
			profile.set_preference( "network.http.sendRefererHeader", 0 )
			profile.set_preference( "javascript.enabled", False )
			profile.set_preference( "permissions.default.image", 2 )
			return webdriver.Firefox(profile)
		elif driverType == 'headless':
			return webdriver.PhantomJS()
		else:
			return webdriver.Firefox() 
开发者ID:toxtli,项目名称:twitter-accounts-creator-bot,代码行数:25,代码来源:accounts.py

示例5: load_localstorage

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxProfile [as 别名]
def load_localstorage(self, session_id):
        sessions = json.load(open( self.sessions_file ))
        storage_path = sessions[str(session_id)]["session_path"]
        url = sessions[str(session_id)]["web_url"]
        # Setting useragent to the same one the session saved with
        useragent = sessions[str(session_id)]["useragent"]
        profile = FirefoxProfile()
        profile.set_preference("general.useragent.override", useragent )
        localStorage = pickle.load(open(storage_path, "rb"))
        try:
            browser = Firefox(profile)
        except:
            error("Couldn't open browser to view session!")
            return
        browser.get(url)
        browser.delete_all_cookies()
        browser.execute_script("window.localStorage.clear()") # clear the current localStorage
        for key,value in localStorage.items():
            browser.execute_script("window.localStorage.setItem(arguments[0], arguments[1]);", key, value)
        status(f"Session {session_id} loaded")
        browser.refresh()
        self.browsers.append(browser) 
开发者ID:OWASP,项目名称:QRLJacking,代码行数:24,代码来源:browser.py

示例6: load_cookie

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxProfile [as 别名]
def load_cookie(self, session_id):
        sessions = json.load(open( self.sessions_file ))
        cookie_path = sessions[str(session_id)]["session_path"]
        url = sessions[str(session_id)]["web_url"]
        # Setting useragent to the same one the session saved with
        useragent = sessions[str(session_id)]["useragent"]
        profile = FirefoxProfile()
        profile.set_preference("general.useragent.override", useragent )
        cookies = pickle.load(open(cookie_path, "rb"))
        try:
            browser = Firefox(profile)
        except:
            error("Couldn't open browser to view session!")
            return
        browser.get(url)
        browser.delete_all_cookies()
        browser.execute_script("window.localStorage.clear()") # clear the current localStorage
        for cookie in cookies:
            browser.add_cookie(cookie)
        status(f"Session {session_id} loaded")
        browser.refresh()
        self.browsers.append(browser) 
开发者ID:OWASP,项目名称:QRLJacking,代码行数:24,代码来源:browser.py

示例7: load_driver

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxProfile [as 别名]
def load_driver(settings):
    """
    Load the Selenium driver depending on the browser
    (Edge and Safari are not running yet)
    """
    driver = None
    if settings['browser'] == 'firefox':
        firefox_profile = webdriver.FirefoxProfile(settings['browser_path'])
        driver = webdriver.Firefox(firefox_profile)
    elif settings['browser'] == 'chrome':
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('user-data-dir=' +
                                    settings['browser_path'])
        driver = webdriver.Chrome(options=chrome_options)
    elif settings['browser'] == 'safari':
        pass
    elif settings['browser'] == 'edge':
        pass

    return driver 
开发者ID:JMGama,项目名称:WhatsApp-Scraping,代码行数:22,代码来源:scraper.py

示例8: firefox

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxProfile [as 别名]
def firefox(headless=True):
    """
    Context manager returning Selenium webdriver.
    Instance is reused and must be cleaned up on exit.
    """
    from selenium import webdriver
    from selenium.webdriver.firefox.options import Options
    if headless:
        driver_key = 'headless'
        firefox_options = Options()
        firefox_options.add_argument('-headless')
    else:
        driver_key = 'headed'
        firefox_options = None
    # Load profile, if it exists:
    if os.path.isdir(PROFILE_DIR):
        firefox_profile = webdriver.FirefoxProfile(PROFILE_DIR)
    else:
        firefox_profile = None
    if FIREFOX_INSTANCE[driver_key] is None:
        FIREFOX_INSTANCE[driver_key] = webdriver.Firefox(
            firefox_profile=firefox_profile,
            firefox_options=firefox_options,
        )
    yield FIREFOX_INSTANCE[driver_key] 
开发者ID:kibitzr,项目名称:kibitzr,代码行数:27,代码来源:launcher.py

示例9: set_firefox_proxy

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxProfile [as 别名]
def set_firefox_proxy(self, profile_dir, proxy_ip, proxy_port):
        """method to update the given preferences in Firefox profile"""
        # Create a default Firefox profile first and update proxy_ip and port
        ff_profile = webdriver.FirefoxProfile(profile_dir)
        proxy_port = int(proxy_port)
        ff_profile.set_preference("network.proxy.type", 1)
        ff_profile.set_preference("network.proxy.http", proxy_ip)
        ff_profile.set_preference("network.proxy.http_port", proxy_port)
        ff_profile.set_preference("network.proxy.ssl", proxy_ip)
        ff_profile.set_preference("network.proxy.ssl_port", proxy_port)
        ff_profile.set_preference("network.proxy.ftp", proxy_ip)
        ff_profile.set_preference("network.proxy.ftp_port", proxy_port)
        ff_profile.update_preferences()

        return ff_profile

    # private methods 
开发者ID:warriorframework,项目名称:warriorframework,代码行数:19,代码来源:browser_mgmt.py

示例10: test_process

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxProfile [as 别名]
def test_process(self):
        from examples import recaptcha_selenium
        from selenium.webdriver import Firefox
        from selenium.webdriver.firefox.options import Options
        from selenium.webdriver import FirefoxProfile

        options = Options()
        options.add_argument("-headless")

        ffprofile = FirefoxProfile()
        ffprofile.set_preference("intl.accept_languages", "en-US")

        driver = Firefox(firefox_profile=ffprofile, firefox_options=options)
        self.assertIn(
            recaptcha_selenium.EXPECTED_RESULT, recaptcha_selenium.process(driver)
        )
        driver.quit() 
开发者ID:ad-m,项目名称:python-anticaptcha,代码行数:19,代码来源:test_examples.py

示例11: firefox_webproxy_driver

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxProfile [as 别名]
def firefox_webproxy_driver(ipport):
    '''
    Use this if you started web proxy on a machine connected to router's LAN.
    '''
    proxy = Proxy({
            'proxyType': 'MANUAL',
            'httpProxy': ipport,
            'ftpProxy': ipport,
            'sslProxy': ipport,
            'noProxy': ''
            })
    print("Attempting to open firefox via proxy %s" % ipport)
    profile = webdriver.FirefoxProfile()
    profile.set_preference('network.http.phishy-userpass-length', 255)
    driver = webdriver.Firefox(proxy=proxy, firefox_profile=profile)
    caps = webdriver.DesiredCapabilities.FIREFOX
    proxy.add_to_capabilities(caps)
    #driver = webdriver.Remote(desired_capabilities=caps)
    driver.implicitly_wait(30)
    driver.set_page_load_timeout(30)
    return driver 
开发者ID:qca,项目名称:boardfarm,代码行数:23,代码来源:common.py

示例12: start_browser

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxProfile [as 别名]
def start_browser():
    # Ensure mobile-friendly view for parsing
    useragent = "Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Mobile Safari/537.36"

    #Firefox
    profile = webdriver.FirefoxProfile()
    profile.set_preference("general.useragent.override", useragent)
    options = webdriver.FirefoxOptions()
    options.set_preference("dom.webnotifications.serviceworker.enabled", False)
    options.set_preference("dom.webnotifications.enabled", False)
    options.add_argument('--headless')

    browser = webdriver.Firefox(firefox_profile=profile,options=options)
    return browser

# Login 
开发者ID:jcontini,项目名称:facebook-friends-map,代码行数:18,代码来源:make.py

示例13: __init__

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxProfile [as 别名]
def __init__(self, proxy):
        """init the webdriver by setting the proxy and user-agent
        
        Args:
            proxy (str): proxy in the form of ip:port
        """
        # set proxy
        ip, port = proxy.split(':')
        profile = webdriver.FirefoxProfile()
        profile.set_preference("network.proxy.type", 1)
        profile.set_preference("network.proxy.http", ip)
        profile.set_preference("network.proxy.http_port", port)
        # set user_agent
        profile.set_preference("general.useragent.override", generate_user_agent())

        profile.update_preferences()
        self.driver = webdriver.Firefox(firefox_profile=profile)
        
        print 'current proxy: %s'%proxy 
开发者ID:WuLC,项目名称:AmazonRobot,代码行数:21,代码来源:Robot.py

示例14: getFirefox

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxProfile [as 别名]
def getFirefox(tempDir='/tmp', showImage=1):
    """get Firefox Webdriver object
    :param showImage: 2 = don't show, 1=show
    """
    proxy = Proxy(dict(proxyType=ProxyType.AUTODETECT))
    profile = webdriver.FirefoxProfile()
    profile.set_preference("plugin.state.flash", 0)
    profile.set_preference("plugin.state.java", 0)
    profile.set_preference("media.autoplay.enabled", False)
    # 2=dont_show, 1=normal
    profile.set_preference("permissions.default.image", showImage)
    profile.set_preference("webdriver.load.strategy", "unstable")
    # automatic download
    # 2 indicates a custom (see: browser.download.dir) folder.
    profile.set_preference("browser.download.folderList", 2)
    # whether or not to show the Downloads window when a download begins.
    profile.set_preference("browser.download.manager.showWhenStarting", False)
    profile.set_preference("browser.download.dir", tempDir)
    profile.set_preference("browser.helperApps.neverAsk.saveToDisk",
                           "application/octet-stream"+
                           ",application/zip"+
                           ",application/x-rar-compressed"+
                           ",application/x-gzip"+
                           ",application/msword")
    return webdriver.Firefox(firefox_profile=profile, proxy=proxy) 
开发者ID:MikimotoH,项目名称:DLink_Harvester,代码行数:27,代码来源:harvest_utils.py

示例15: setUp

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import FirefoxProfile [as 别名]
def setUp(self):
        self.url = 'http://localhost:8000/checkin/'
        fp = webdriver.FirefoxProfile()
        if os.getenv('DISABLE_COOKIES'):
            fp.set_preference('network.cookie.cookieBehavior', 2)
        self.browser = webdriver.Firefox(firefox_profile=fp)
        self.browser.implicitly_wait(3)
        self.browser.get(self.url) 
开发者ID:fpsw,项目名称:Servo,代码行数:10,代码来源:test_functional.py


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