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


Python webdriver.Firefox方法代码示例

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


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

示例1: test_webdriver2

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Firefox [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: test_firefoxwebdriver

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Firefox [as 别名]
def test_firefoxwebdriver(self):
        browser = webdriver.Firefox()
        browser.maximize_window()
        try:
            url = 'http://data.eastmoney.com/hsgtcg/StockStatistics.aspx'
            browser.get(url)
            # 北向持股
            browser.find_element_by_css_selector('.border_left_1').click()
            time.sleep(0.2)
            # 自定义区间
            browser.find_element_by_css_selector('.custom-text > span:nth-child(1)').click()
            time.sleep(0.5)
            # 开始日期赋值
            tdate = browser.find_element_by_css_selector('input.date-input:nth-child(1)')
            tdate.send_keys(str(datetime.datetime.now().date()-datetime.timedelta(10)))
            time.sleep(0.5)
            tdate = browser.find_element_by_css_selector('.search-btn')
            time.sleep(5)

        finally:
            if browser:
                browser.close() 
开发者ID:pchaos,项目名称:wanggeService,代码行数:24,代码来源:test_HSGTCGHold.py

示例3: test_webdriver

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Firefox [as 别名]
def test_webdriver(self):
        from selenium.webdriver.common.proxy import Proxy, ProxyType
        myProxy = "127.0.0.1:8123"
        myProxy = "192.168.103.1:1081"
        desired_capability = webdriver.DesiredCapabilities.FIREFOX
        desired_capability['proxy'] = {
            "proxyType": "manual",
            "httpProxy": myProxy,
            "ftpProxy": myProxy,
            "sslProxy": myProxy
        }
        try:
            browser = webdriver.Firefox(capabilities=desired_capability, timeout=30)
            url = "http://data.eastmoney.com/hsgtcg/StockHdDetail.aspx?stock=600519&date=2018-06-12/"
            browser.get(url)
            time.sleep(25)
        finally:
            print(myProxy)
            browser.quit() 
开发者ID:pchaos,项目名称:wanggeService,代码行数:21,代码来源:test_get_proxy.py

示例4: __init__

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Firefox [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

示例5: getWebDriver

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Firefox [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

示例6: getWebdriver

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Firefox [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

示例7: setup_class

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Firefox [as 别名]
def setup_class(self):
        """
        Setup: Open a mozilla browser, login
        """
        self.browser = Firefox()
        self.browser.get('http://localhost:5000/')
        token = self.browser.find_element_by_name("token")
        password = "foo"
        # login
        token.send_keys(password)
        token.send_keys(Keys.ENTER)
        time.sleep(.1)
        try:
            self.browser.find_element_by_xpath("//input[@value='Logout']")
        except NoSuchElementException:
            raise ValueError("Can't login!!! Create a user 'foo' with the permissions"
                             "'read' and 'create' in your PERMISSIONS in the config") 
开发者ID:bepasty,项目名称:bepasty-server,代码行数:19,代码来源:test_website.py

示例8: start_captcha

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Firefox [as 别名]
def start_captcha():
    driver = webdriver.Firefox()
    driver.get("http://reddit.com")
    driver.find_element(By.XPATH, "//*[@id=\"header-bottom-right\"]/span[1]/a").click()
    time.sleep(1)
    driver.find_element(By.ID, "user_reg").send_keys("qwertyuiop091231")
    driver.find_element(By.ID, "passwd_reg").send_keys("THISISMYPASSWORD!!$")
    driver.find_element(By.ID, "passwd2_reg").send_keys("THISISMYPASSWORD!!$")
    driver.find_element(By.ID, "email_reg").send_keys("biggie.smalls123@gmail.com")
    #driver.find_element_by_tag_name("body").send_keys(Keys.COMMAND + Keys.ALT + 'k')
    iframeSwitch = driver.find_element(By.XPATH, "//*[@id=\"register-form\"]/div[6]/div/div/div/iframe")
    driver.switch_to.frame(iframeSwitch)
    driver.find_element(By.ID, "recaptcha-anchor").click()
    # download captcha image
    # 
    # split payload
    # 
    # reverse_search
    # 
    # driver.quit()

# determines if an image keywords matches the target keyword
# uses the synonyms of the image keyword 
开发者ID:ecthros,项目名称:uncaptcha,代码行数:25,代码来源:ris.py

示例9: get_driver

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Firefox [as 别名]
def get_driver(self):
        # Start a new browser and return the WebDriver

        browser_name = self.config.get('selenium', 'browser')

        if browser_name == 'firefox':
            from selenium.webdriver import Firefox

            return Firefox()

        if browser_name == 'chrome':
            from selenium.webdriver import Chrome

            return Chrome()

        if browser_name == 'phantomjs':
            from selenium.webdriver import PhantomJS

            return PhantomJS()

        # @TODO: Add chrome
        raise RuntimeError('Unsupported/unknown browser') 
开发者ID:scriptotek,项目名称:alma-slipsomat,代码行数:24,代码来源:worker.py

示例10: load_localstorage

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Firefox [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

示例11: load_cookie

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Firefox [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

示例12: convertHeadless

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Firefox [as 别名]
def convertHeadless(driver, url):
	#converts a phantomjs browser to a firefox webdriver window
	cookies = driver.get_cookies()
	#saves cookies as dict
	driver.quit()
	#closes the phantomjs window
	driver = webdriver.Firefox()
	#replaces phantomjs instance with firefox browser
	driver.get(url)
	# has to go to the url before adding cookies
	# If you were doing this with shoes - it should show an empty cart
	for cookie in cookies:
		#adds cookies to the driver
		driver.add_cookie(cookie)
	driver.get(url)
	# this will reload the url with the cookies you imported
	return driver 
开发者ID:theriley106,项目名称:SneakerBotTutorials,代码行数:19,代码来源:main.py

示例13: createHeadlessBrowser

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Firefox [as 别名]
def createHeadlessBrowser(proxy=None, XResolution=1024, YResolution=768, timeout=20):
	#proxy = None
	if TEST_MODE == False:
		dcap = dict(DesiredCapabilities.PHANTOMJS)
		dcap["phantomjs.page.settings.userAgent"] = (
		    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.86 Safari/537.36')
		# Fake browser headers
		if proxy != None:
			# This means the user set a proxy
			service_args = ['--proxy={}'.format(proxy),'--proxy-type=https','--ignore-ssl-errors=true', '--ssl-protocol=any', '--web-security=false',]
			driver = webdriver.PhantomJS(service_args=service_args, desired_capabilities=dcap)
		else:
			# No proxy was set by the user
			driver = webdriver.PhantomJS(desired_capabilities=dcap)
		driver.set_window_size(XResolution,YResolution)
		# Sets the screen resolution
		# Ideally this will be dynamic based on the number of browsers open
		driver.set_page_load_timeout(timeout)
		# Sets the timeout for the selenium window
	else:
		driver = webdriver.Firefox()
	return driver
	# Returns driver instance 
开发者ID:theriley106,项目名称:SneakerBotTutorials,代码行数:25,代码来源:main.py

示例14: setUp

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Firefox [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

示例15: _setup_firefox

# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Firefox [as 别名]
def _setup_firefox(self, capabilities):
        """Setup Firefox webdriver

        :param capabilities: capabilities object
        :returns: a new local Firefox driver
        """
        if capabilities.get("marionette"):
            gecko_driver = self.config.get('Driver', 'gecko_driver_path')
            self.logger.debug("Gecko driver path given in properties: %s", gecko_driver)
        else:
            gecko_driver = None

        # Get Firefox binary
        firefox_binary = self.config.get_optional('Firefox', 'binary')

        firefox_options = Options()

        if self.config.getboolean_optional('Driver', 'headless'):
            self.logger.debug("Running Firefox in headless mode")
            firefox_options.add_argument('-headless')

        self._add_firefox_arguments(firefox_options)

        if firefox_binary:
            firefox_options.binary = firefox_binary

        log_path = os.path.join(DriverWrappersPool.output_directory, 'geckodriver.log')
        try:
            # Selenium 3
            return webdriver.Firefox(firefox_profile=self._create_firefox_profile(), capabilities=capabilities,
                                     executable_path=gecko_driver, firefox_options=firefox_options, log_path=log_path)
        except TypeError:
            # Selenium 2
            return webdriver.Firefox(firefox_profile=self._create_firefox_profile(), capabilities=capabilities,
                                     executable_path=gecko_driver, firefox_options=firefox_options) 
开发者ID:Telefonica,项目名称:toolium,代码行数:37,代码来源:config_driver.py


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