當前位置: 首頁>>代碼示例>>Python>>正文


Python Options.set_headless方法代碼示例

本文整理匯總了Python中selenium.webdriver.firefox.options.Options.set_headless方法的典型用法代碼示例。如果您正苦於以下問題:Python Options.set_headless方法的具體用法?Python Options.set_headless怎麽用?Python Options.set_headless使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在selenium.webdriver.firefox.options.Options的用法示例。


在下文中一共展示了Options.set_headless方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: startMobileDriver

# 需要導入模塊: from selenium.webdriver.firefox.options import Options [as 別名]
# 或者: from selenium.webdriver.firefox.options.Options import set_headless [as 別名]
    def startMobileDriver(self):

        options = Options()
        options.set_headless(self.useHeadless)
        if self.loadDefaultProfile == True:
            firefoxMobileProfile = webdriver.FirefoxProfile(profile_directory=self.ffProfileDir)
        else:
            firefoxMobileProfile = None
        if self.mobileUA != None:
            firefoxMobileProfile.set_preference("general.useragent.override", self.mobileUA)

        self.firefoxMobileDriver = webdriver.Firefox(
            firefox_profile=firefoxMobileProfile, executable_path=self.driverBinary, firefox_options=options)
        self.mobileRunning = True
        if self.loadCookies == True and self.cookies != None:
            self.firefoxMobileDriver.delete_all_cookies()
            # Loading cookies only works if we are at a site the cookie would work for
            self.getMobileUrl("https://login.live.com")
            for cookie in self.cookies:
                # print("Adding cookie to Firefox Mobile Driver: %s" % str(cookie))
                # new_cookie = {}
                # new_cookie['name'] = cookie['name']
                # new_cookie['value'] = cookie['value']
                try:
                    self.firefoxMobileDriver.add_cookie(cookie)
                except selenium.common.exceptions.InvalidCookieDomainException:
                    contine
開發者ID:jprince14,項目名稱:BingTool,代碼行數:29,代碼來源:FirefoxWebDriver.py

示例2: redeem

# 需要導入模塊: from selenium.webdriver.firefox.options import Options [as 別名]
# 或者: from selenium.webdriver.firefox.options.Options import set_headless [as 別名]
def redeem(codes, headless=True):
    try:
        opts = Options()
        if headless:
            opts.set_headless()
        ffprofile = webdriver.FirefoxProfile(settings.firefox_profile_path)
        browser = webdriver.Firefox(firefox_profile=ffprofile, options=opts)
        browser.get('http://www.marvel.com/redeem')
        redeem_code(browser, codes)
        browser.quit()
    except:
        logging.error('Unable to redeem: %s' % ','.join(codes))
開發者ID:benosment,項目名稱:reddit_comic,代碼行數:14,代碼來源:redeem.py

示例3: EventsList

# 需要導入模塊: from selenium.webdriver.firefox.options import Options [as 別名]
# 或者: from selenium.webdriver.firefox.options.Options import set_headless [as 別名]
def EventsList(events_url):
    options = Options()                                                                                         #Grabs the first 4 events from the events page
    options.set_headless(headless=True)
    browser = webdriver.Firefox(firefox_options=options)
    try:
        browser.get(events_url) 
        innerHTML = browser.execute_script("return document.body.innerHTML")
        test = (browser.page_source)
        browser.quit()
    except:
        test = "null"
    try:
        text = test.split('hovercard/event.php?id=')[1]
        text1 = text.split('hovercard/event.php?id=')[0]
        text1 = text1.split('"')[0]
        latest = text1
    except:
        logs.print2("Couldn't extract latest event id")
        latest = "null"
    try:
        text = test.split('hovercard/event.php?id='+text1)[1]
        text2 = text.split('hovercard/event.php?id=')[1]
        text2 = text2.split('hovercard/event.php?id=')[0]
        text2 = text2.split('"')[0]
        first = text2
    except:
        logs.print2("Couldn't extract first event id")
        first = "null"
    try:
        text = test.split('hovercard/event.php?id='+text2)[1]
        text3 = text.split('hovercard/event.php?id=')[1]
        text3 = text3.split('hovercard/event.php?id=')[0]
        text3 = text3.split('"')[0]
        second = text3
    except:
        logs.print2("Couldn't extract second event id")
        second = "null"
    try:
        text = test.split('hovercard/event.php?id='+text3)[1]
        text4 = text.split('hovercard/event.php?id=')[1]
        text4 = text4.split('hovercard/event.php?id=')[0]
        text4 = text4.split('"')[0]
        third = text4
    except:
        logs.print2("Couldn't extract third event id")
        third = "null"
    return (latest,first,second,third)
開發者ID:GeorgeGrig,項目名稱:Event-Crawler,代碼行數:49,代碼來源:fb.py

示例4: _get_Firefox

# 需要導入模塊: from selenium.webdriver.firefox.options import Options [as 別名]
# 或者: from selenium.webdriver.firefox.options.Options import set_headless [as 別名]
    def _get_Firefox(self):

        try:
            bin_path = self.config.get('firefox_binary_path')
            binary = FirefoxBinary(bin_path)
            geckodriver_path = self.config.get('geckodriver_path')
            options = FirefoxOptions()
            profile = webdriver.FirefoxProfile()

            options.add_argument(
                'user-agent={}'.format(self.user_agent))

            if self.browser_mode == 'headless':
                options.set_headless(headless=True)
                #options.add_argument('window-size=1200x600') # optional

            if self.proxy:
                # this means that the proxy is user set, regardless of the type
                profile.set_preference("network.proxy.type", 1)
                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_binary=binary, firefox_options=options,
                     executable_path=geckodriver_path, firefox_profile=profile)
            return True

        except WebDriverException as e:
            # reaching here is bad, since we have no available webdriver instance.
            logger.error(e)

        return False
開發者ID:NikolaiT,項目名稱:GoogleScraper,代碼行數:43,代碼來源:selenium_mode.py

示例5: Options

# 需要導入模塊: from selenium.webdriver.firefox.options import Options [as 別名]
# 或者: from selenium.webdriver.firefox.options.Options import set_headless [as 別名]
import random
import time
import asyncio
import threading
from concurrent import futures

from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options


options = Options()
options.set_headless()
# options.add_arguments("--disable-notifications")


debug = True

duration = 4


url = 'https://telugu.pratilipi.com/read?id=6755373518909383'

# proverbs
url = 'https://telugu.pratilipi.com/read?id=6755373518926758'


def read_url(url):
    driver = Firefox(options=options)
    driver.maximize_window()
    driver.get(url)
    time.sleep(4)
開發者ID:ChillarAnand,項目名稱:01,代碼行數:33,代碼來源:selenium_exp.py

示例6: FirefoxBinary

# 需要導入模塊: from selenium.webdriver.firefox.options import Options [as 別名]
# 或者: from selenium.webdriver.firefox.options.Options import set_headless [as 別名]
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('/home/nikolai/ff/firefox/firefox')

options = Options()
options.set_headless(headless=True)
driver = webdriver.Firefox(firefox_binary=binary,
    firefox_options=options, executable_path='../Drivers/geckodriver')
driver.get("http://google.com/")
print ("Headless Firefox Initialized")
driver.quit()
開發者ID:NikolaiT,項目名稱:GoogleScraper,代碼行數:15,代碼來源:headless-firefox.py

示例7: EventData

# 需要導入模塊: from selenium.webdriver.firefox.options import Options [as 別名]
# 或者: from selenium.webdriver.firefox.options.Options import set_headless [as 別名]
def EventData(event_id):
    url = 'https://www.facebook.com/events/'+event_id
    try:
        fp = urllib.request.urlopen(url)
        mybytes = fp.read()
        mystr = mybytes.decode("utf8")
        fp.close()
    except:
        logs.print2("Couldn't load page")
        mystr = "null"
    #########gets event name
    try:
        text = mystr.split('data-testid="event-permalink-event-name">')[1]
        event_name = text.split('</h1')[0]
        if "&quot;" in event_name:
            event_name = event_name.replace("&quot;", '"')
        if "&#039;" in event_name:
            event_name = event_name.replace("&#039;", "'")
    except:
        logs.print2("Couldn't extract event name,god damn it facebook")
        event_name = "Couldn't extract event name"
    #########gets event date
    try:
        text = mystr.split('<span itemprop="startDate">')[1]
        text_left = text.split('</span>')[0]
        text_left = text_left+" "
        number_length = 4                                     
        pattern= r"\D(\d{%d})\D" % number_length      
        test = re.findall(pattern, text_left)
        if not test:
            now = datetime.datetime.now()
            event_date = text_left+" " + str(now.year)
        else:
            event_date = text_left 
    except:
        logs.print2("Couldn't extract event date,god damn it facebook")
        event_date = "Couldn't extract event date"
    #########gets event description
    options = Options()
    options.set_headless(headless=True)
    driver = webdriver.Firefox(firefox_options=options)
    try:       
        driver.get(url)
    except:
        logs.print2("Couldn't load page for event description")
    try:
        WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'uiContextualLayerParent')))
        time.sleep(20)
    except TimeoutException:
        print('Page timed out after 10 secs.')
    try:
        soup = BeautifulSoup(driver.page_source, 'html.parser')
        driver.quit()
        text = soup.text.split('φίλους σας')[1]
        event_description = text.split('Δείτε τη συζήτηση')[0]
        event_description = event_description.split('Λεπτομέρειες')[1]
        event_description = event_description.split('Δείτε περισσότεραΠληροφορίες')[0]
    except:
        logs.print2("Couldn't extract event description,god damn it facebook")
        event_description = "Couldn't extract event description"
    return (event_description,event_date,event_name)
開發者ID:GeorgeGrig,項目名稱:Event-Crawler,代碼行數:63,代碼來源:fb.py

示例8: __init__

# 需要導入模塊: from selenium.webdriver.firefox.options import Options [as 別名]
# 或者: from selenium.webdriver.firefox.options.Options import set_headless [as 別名]
    def __init__(self, client="firefox", username="API", proxy=None, command_executor=None, loadstyles=False,
                 profile=None, headless=False, autoconnect=True, logger=None, extra_params=None, chrome_options=None):
        """Initialises the webdriver"""

        self.logger = logger or self.logger
        extra_params = extra_params or {}

        if profile is not None:
            self._profile_path = profile
            self.logger.info("Checking for profile at %s" % self._profile_path)
            if not os.path.exists(self._profile_path):
                self.logger.critical("Could not find profile at %s" % profile)
                raise WhatsAPIException("Could not find profile at %s" % profile)
        else:
            self._profile_path = None

        self.client = client.lower()
        if self.client == "firefox":
            if self._profile_path is not None:
                self._profile = webdriver.FirefoxProfile(self._profile_path)
            else:
                self._profile = webdriver.FirefoxProfile()
            if not loadstyles:
                # Disable CSS
                self._profile.set_preference('permissions.default.stylesheet', 2)
                # Disable images
                self._profile.set_preference('permissions.default.image', 2)
                # Disable Flash
                self._profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
                                             'false')
            if proxy is not None:
                self.set_proxy(proxy)

            options = Options()

            if headless:
                options.set_headless()

            options.profile = self._profile

            capabilities = DesiredCapabilities.FIREFOX.copy()
            capabilities['webStorageEnabled'] = True

            self.logger.info("Starting webdriver")
            self.driver = webdriver.Firefox(capabilities=capabilities, options=options, **extra_params)

        elif self.client == "chrome":
            self._profile = webdriver.ChromeOptions()
            if self._profile_path is not None:
                self._profile.add_argument("user-data-dir=%s" % self._profile_path)
            if proxy is not None:
                self._profile.add_argument('--proxy-server=%s' % proxy)
            if headless:
                self._profile.add_argument('headless')
            if chrome_options is not None:
                for option in chrome_options:
                    self._profile.add_argument(option)
            self.logger.info("Starting webdriver")
            self.driver = webdriver.Chrome(chrome_options=self._profile, **extra_params)

        elif client == 'remote':
            if self._profile_path is not None:
                self._profile = webdriver.FirefoxProfile(self._profile_path)
            else:
                self._profile = webdriver.FirefoxProfile()
            capabilities = DesiredCapabilities.FIREFOX.copy()
            self.driver = webdriver.Remote(
                command_executor=command_executor,
                desired_capabilities=capabilities,
                **extra_params
            )

        else:
            self.logger.error("Invalid client: %s" % client)
        self.username = username
        self.wapi_functions = WapiJsWrapper(self.driver, self)

        self.driver.set_script_timeout(500)
        self.driver.implicitly_wait(10)

        if autoconnect:
            self.connect()
開發者ID:hifenhur,項目名稱:wppbot,代碼行數:84,代碼來源:__init__.py


注:本文中的selenium.webdriver.firefox.options.Options.set_headless方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。