Python selenium.webdriver 模块,Firefox() 实例源码

我们从Python开源项目中,提取了以下47个代码示例,用于说明如何使用selenium.webdriver.Firefox()

项目:OpenCouture-Dev    作者:9-9-0    | 项目源码 | 文件源码
def inspectCart2(self):
        print '\nINSPECT CART ----------------'
        self.get_headers['Accept-Encoding'] = 'gzip, deflate, sdch, br'
        self.get_headers['Referer'] = self.URL_product_url
        session_get = self.user_session.get(url=self.URL_cart_url, headers=self.get_headers)

        print 'Inspect Cart Status: ' + str(session_get.status_code)

        cookies = self.user_session.cookies.get_dict()
        with open('injectCookies', 'wb') as output:
            output.write(json.dumps(cookies, indent=1))

        driver = webdriver.Firefox()
        driver.get(self.URL_cart_url)
        driver.add_cookie(cookies)
        driver.get(self.URL_cart_url)
项目:biweeklybudget    作者:jantman    | 项目源码 | 文件源码
def chrome(self):
        # https://github.com/SeleniumHQ/selenium/blob/master/py/selenium/webdriver/remote/webdriver.py
        # http://www.guguncube.com/2983/python-testing-selenium-with-google-chrome
        # https://gist.github.com/addyosmani/5336747
        # http://blog.likewise.org/2015/01/setting-up-chromedriver-and-the-selenium-webdriver-python-bindings-on-ubuntu-14-dot-04/
        # https://sites.google.com/a/chromium.org/chromedriver/getting-started
        # http://stackoverflow.com/questions/8255929/running-webdriver-chrome-with-selenium
        chrome = webdriver.Chrome()
        return chrome

#     @property
#     def firefox(self):
#         profile = webdriver.FirefoxProfile()
#         #firefox = webdriver.Firefox(firefox_profile=profile)
#         firefox = WebDriver(firefox_profile=profile)
#         return firefox
项目:Facebook-Photos-Download-Bot    作者:NalinG    | 项目源码 | 文件源码
def main(username, account_password,destination):
    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', destination)
    profile.set_preference('browser.helperApps.neverAsk.saveToDisk', "image/png,image/jpeg")

    if not username == "NONE" and not account_password == "NONE" and not destination == "NONE":
        display = Display(visible=0, size=(800, 600))
            display.start()
        driver = webdriver.Firefox(firefox_profile=profile)
        driver.get("https://www.facebook.com")

        email_id = driver.find_element_by_id("email")
        password = driver.find_element_by_id("pass")
        email_id.send_keys(username)
        password.send_keys(account_password)
        driver.find_element_by_id("loginbutton").click()
        # driver.find_element_by_css_selector("._5afe.sortableItem").click()
        driver.find_element_by_id("navItem_2305272732").click()
        time.sleep(3)
        list_of_images = driver.find_elements_by_css_selector(".uiMediaThumbImg")
        list_of_images[0].click()
        # print list_of_images
        for image in list_of_images:
            time.sleep(3)
            driver.find_element_by_xpath("//div[@class = 'overlayBarButtons rfloat _ohf']/div/div/a").click()
            time.sleep(3)
            option = driver.find_element_by_xpath("//div[@class = 'uiContextualLayerPositioner uiLayer']/div/div/div[@class = '_54ng']/ul[@class = '_54nf']/li[4]/a")
            option_name = option.find_element_by_xpath(".//*")
            option_name = option_name.find_element_by_xpath(".//*")
            if option_name.get_attribute('innerHTML').lower() == "download":
                option_name.click()
            # print option.get_attribute('innerHTML')
            driver.find_element_by_css_selector(".snowliftPager.next.hilightPager").click()

            display.stop()

    else:
        print "\nIncomplete Parameters, Program is Shutting Down."
项目:PyWebRunner    作者:IntuitiveWebSolutions    | 项目源码 | 文件源码
def get_js_errors(self):
        '''
        Uses the JSErrorCollector plugin for Chrome / Firefox to get any JS errors.

        [
            {
                'sourceName': u'tests/html/js_error.html',
                'pageUrl': u'tests/html/js_error.html',
                'errorMessage': 'ReferenceError: b is not defined',
                'lineNumber': 7
            }
        ]
        '''
        if self.driver in ('Chrome', 'Firefox'):
            return self.js('return window.JSErrorCollector_errors ? window.JSErrorCollector_errors.pump() : []')
        else:
            print("Checking for JS errors with this method only works in Firefox or Chrome")
            return []
项目:PythonStudyCode    作者:TongTongX    | 项目源码 | 文件源码
def login():
    driver = webdriver.Firefox()

    driver.implicitly_wait(10)

    driver.get("https://www.facebook.com")
    driver.find_element_by_id('email').send_keys("email_address")
    driver.find_element_by_id('pass').send_keys("password")
    driver.find_element_by_id('u_0_n').click()

    '''
    time.sleep(1)
    print "------- login ---------"
    email = driver.find_element_by_id('email')
    email.send_keys("email_address")
    time.sleep(1)
    password = driver.find_element_by_id('pass')
    password.send_keys("password")
    time.sleep(1)
    password.send_keys(Keys.RETURN)
    time.sleep(2)
    driver.get("https://www.facebook.com")
    time.sleep(1)
    pickle.dump(driver.get_cookies(), open("cookies.pkl", "w"))
    '''
项目:warriorframework    作者:warriorframework    | 项目源码 | 文件源码
def set_firefoxprofile(proxy_ip, proxy_port):
        """method to update the given preferences in Firefox profile"""
        ff_profile = webdriver.FirefoxProfile()
        if proxy_ip is not None and proxy_port is not None:
            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()
        else:
            ff_profile = None
        return ff_profile

    # private methods
项目:warriorframework    作者:warriorframework    | 项目源码 | 文件源码
def _make_ff(self, webdriver_remote_url, desired_capabilites, profile_dir,
                 binary, gecko_path):
        """Create an instance of firefox browser"""
        try:
            if webdriver_remote_url:
                browser = self._create_remote_web_driver(
                        webdriver.DesiredCapabilities.FIREFOX,
                        webdriver_remote_url, desired_capabilites,
                        profile_dir)
            else:
                ff_capabilities = webdriver.DesiredCapabilities.FIREFOX
                if ff_capabilities['marionette']:
                    ff_capabilities['acceptInsecureCerts'] = True
                    ffbinary = FirefoxBinary(binary)
                    browser = webdriver.Firefox(firefox_binary=ffbinary,
                                                firefox_profile=profile_dir,
                                                executable_path=gecko_path)
                else:
                    browser = webdriver.Firefox(firefox_profile=profile_dir)
            return browser
        except WebDriverException as e:
            if "executable needs to be in PATH" in str(e):
                print_error("Please provide path for geckodriver executable")
            elif "Expected browser binary location" in str(e):
                print_error("Please provide path of firefox executable")
项目:core-python    作者:yidao620c    | 项目源码 | 文件源码
def click_page():
    driver = webdriver.Firefox()
    driver.get('http://yidao620c.github.io/archives/')
    driver.maximize_window()
    len1 = len(driver.find_elements_by_xpath(
                '//div[@class="post-archive"]/ul[@class="listing"]/li/a'))
    _log.info('????????...')
    for k in range(1, 100):
        logging.info('?{}???...'.format(k))
        for i in range(0, len1):
            l_xpath = '(//div[@class="post-archive"]/ul[@class="listing"]/li/a)[{}]'.format(i + 1)
            ele = WebDriverWait(driver, 2).until(
                EC.presence_of_element_located((By.XPATH, l_xpath))
            )
            ele.click()
            driver.back()

    _log.info('all finished.')
    driver.close()
项目:isar    作者:ilbers    | 项目源码 | 文件源码
def create_selenium_driver(browser='chrome'):
    # set default browser string based on env (if available)
    env_browser = os.environ.get('TOASTER_TESTS_BROWSER')
    if env_browser:
        browser = env_browser

    if browser == 'chrome':
        return webdriver.Chrome(
            service_args=["--verbose", "--log-path=selenium.log"]
        )
    elif browser == 'firefox':
        return webdriver.Firefox()
    elif browser == 'marionette':
        capabilities = DesiredCapabilities.FIREFOX
        capabilities['marionette'] = True
        return webdriver.Firefox(capabilities=capabilities)
    elif browser == 'ie':
        return webdriver.Ie()
    elif browser == 'phantomjs':
        return webdriver.PhantomJS()
    else:
        msg = 'Selenium driver for browser %s is not available' % browser
        raise RuntimeError(msg)
项目:DLink_Harvester    作者:MikimotoH    | 项目源码 | 文件源码
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)
项目:Django-Web-Development-with-Python    作者:PacktPublishing    | 项目源码 | 文件源码
def setUpClass(cls):
        super(LiveLocationTest, cls).setUpClass()
        cls.browser = webdriver.Firefox()
        cls.browser.delete_all_cookies()
        cls.location = Location.objects.create(
            title="Haus der Kulturen der Welt",
            slug="hkw",
            small_image="locations/2015/11/20151116013056_small.jpg",
            medium_image="locations/2015/11/20151116013056_medium.jpg",
            large_image="locations/2015/11/20151116013056_large.jpg",
        )
        cls.username = "test-admin"
        cls.password = "test-admin"
        cls.superuser = User.objects.create_superuser(
            username=cls.username,
            password=cls.password,
            email="",
        )
项目:cabu    作者:thylong    | 项目源码 | 文件源码
def load_driver(config, vdisplay=None):
    """Initialize a weddriver selected in config with given config.

    Args:
        config (dict): The configuration loaded previously in Cabu.

    Returns:
        webdriver (selenium.webdriver): An instance of selenium webdriver or None.
    """

    if config['DRIVER_NAME'] == 'Firefox':
        driver = load_firefox(config)
    elif config['DRIVER_NAME'] == 'Chrome':
        driver = load_chrome(config)
    elif config['DRIVER_NAME'] == 'PhantomJS':
        driver = load_phantomjs(config)
    elif not config.get('DRIVER_NAME'):
        return None
    else:
        raise DriverException(vdisplay, 'Driver unrecognized.')

    driver.set_page_load_timeout(config['DRIVER_PAGE_TIMEOUT'])
    driver.set_window_size(config['DRIVER_WINDOWS_WIDTH'], config['DRIVER_WINDOWS_HEIGHT'])

    return driver
项目:voamos    作者:miguelsc    | 项目源码 | 文件源码
def init_driver(self):
        global driver

        if self.is_initialized:
            return

        if self.driver_name == 'chrome':
            driver = webdriver.Chrome(executable_path=self.driver_path)
        elif self.driver_name == 'phantomjs':
            driver = webdriver.PhantomJS(executable_path=self.driver_path)
        elif self.driver_name == 'firefox':
            driver = webdriver.Firefox(executable_path=self.driver_path)
        else:
            raise Exception(
                'Driver "{}" is not supported'.format(self.driver_name))

        self.is_initialized = True
        driver.set_window_size(self.width, self.height)
        driver.implicitly_wait(5)
项目:EasyCrawler    作者:playwolf719    | 项目源码 | 文件源码
def process_request(self, request, spider):
        try:
            driver = webdriver.PhantomJS() #????????
             # driver = webdriver.Firefox()
            print "---"+str(request.meta["page"])+"-----js url start-------"
            print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            driver.get(self.pc_index_url+"&page="+str(request.meta["page"]) )
            # time.sleep(1)
            tmp=driver.find_element_by_id('sf-item-list-data').get_attribute("innerHTML")
            print "---"+str(request.meta["page"])+"-----js url end-------"
            print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            body = tmp
            return HtmlResponse(driver.current_url, body=body, encoding='utf-8', request=request)
        except Exception,e:
            print "-------------------"
            print e.__doc__
            print e.message
            print "-------------------"
项目:automation-design-patterns    作者:paulbodean88    | 项目源码 | 文件源码
def get_selenium_driver(browser_name: str) -> Union[Chrome, Firefox]:
    """
    Return the same instance to the Selenium driver.

    :param browser_name: the name of the browser: chrome or mozilla
    :type browser_name: str
    :return: an instance of the required driver.
    :rtype: Union[Chrome, Mozilla]
    """
    if browser_name.upper() == 'CHROME':
        return SingletonFactory.build(Chrome)

    elif browser_name.upper() == 'Mozilla':
        return SingletonFactory.build(Firefox)

    else:
        raise NotImplementedError
项目:taobao    作者:chifeng111    | 项目源码 | 文件源码
def get_page(key_words):
    html = []
    b = webdriver.PhantomJS(executable_path="phantomjs.exe")
    #b = webdriver.Firefox()
    b.get("https://world.taobao.com/")
    time.sleep(3)
    b.find_element_by_id('q').send_keys(key_words)
    b.find_element_by_xpath('/html/body/div[1]/div[2]/div/div/div/div[2]/div[1]/div[2]/form/div[1]/button').click()
    time.sleep(3)
    b.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    b.maximize_window()
    html.append(b.page_source.encode('gbk', 'ignore'))
    for i in range(99):
        b.find_element_by_xpath('/html/body/div[5]/div[4]/div/div[1]/div[1]/div[4]/div/div/a[last()]/span').click()
        page = str(i+1)
        time.sleep(5)
        b.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        html.append(b.page_source.encode('gbk', 'ignore'))
        print("?????%s?" %page)
    b.close()
    return html

#/html/body/div[5]/div[4]/div/div[1]/div[1]/div[4]/div/div/a[last()]/span
#/html/body/div[5]/div[4]/div/div[1]/div[1]/div[4]/div/div/a[7]/span
项目:Hanhan_NLP    作者:hanhanwu    | 项目源码 | 文件源码
def main():
    comment_urls = [
        "http://www.theglobeandmail.com/opinion/a-fascists-win-americas-moral-loss/article32753320/comments/"
                   ]

    for comment_url in comment_urls:
        driver = webdriver.Firefox()
        driver.get(comment_url)
        time.sleep(5)
        htmlSource = driver.page_source
        clk = driver.find_element_by_css_selector('div.c3qHyJD')
        clk.click()
        reaction_counts = driver.find_elements_by_class_name('c2oytXt')
        for rc in reaction_counts:
            print(rc.text)
        driver.close()   # close the browser
项目:AmazonRobot    作者:WuLC    | 项目源码 | 文件源码
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
项目:nextcloud    作者:syncloud    | 项目源码 | 文件源码
def driver():

    if exists(screenshot_dir):
        shutil.rmtree(screenshot_dir)
    os.mkdir(screenshot_dir)

    firefox_path = '{0}/firefox/firefox'.format(DIR)
    caps = DesiredCapabilities.FIREFOX
    caps["marionette"] = True
    caps['acceptSslCerts'] = True

    binary = FirefoxBinary(firefox_path)

    profile = webdriver.FirefoxProfile()
    profile.add_extension('{0}/JSErrorCollector.xpi'.format(DIR))
    profile.set_preference('app.update.auto', False)
    profile.set_preference('app.update.enabled', False)
    driver = webdriver.Firefox(profile,
                               capabilities=caps, log_path="{0}/firefox.log".format(LOG_DIR),
                               firefox_binary=binary, executable_path=join(DIR, 'geckodriver/geckodriver'))
    # driver.set_page_load_timeout(30)
    # print driver.capabilities['version']
    return driver
项目:kungahusgranskning    作者:jplusplus    | 项目源码 | 文件源码
def scrape_until(self, year):
        """ Scrape all calender events from today until a given year.
            Returns data as a list of dicts.
        """
        self.driver = webdriver.Firefox()
        self.start_url = "http://kongehuset.dk/menu/kalender"

        # Get a list of all persons
        self._open_calendar()

        data = []
        current_date = self.get_current_year_and_month()
        while current_date["year"] > year:
            print ("Parse %s, %s" % (current_date["month"], current_date["year"]))
            month_data = self._parse_calender()
            data += month_data
            sleep(1)
            self._go_to_previous_month()
            current_date = self.get_current_year_and_month()

        self.data = data
        return data
项目:pyEbaySniper    作者:braph    | 项目源码 | 文件源码
def setup_vars():
    reg_variable('USER',     'User for ebay')
    reg_variable('PASSWORD', 'Password for ebay')
    reg_variable('DRIVER',   'Driver to use with selenium', 'PhantomJS',
        validate=lambda v: v in ('Chrome', 'Firefox', 'PhantomJS')
    )
    reg_variable('LOCALE',   'Localization for numerics and monetary stuff',
        validate=lambda v: locale.setlocale(locale.LC_ALL, v)
    )
    reg_variable('BID_AHEAD_SECONDS', 'How many seconds before the actually specified time the bid should be placed',
        value=3, type=int
    )
    reg_variable('HISTORY',   'History file',
        os.path.expanduser("~/.ebay_hist")
    )
    #reg_variable('COOKIE_FILE', 'File for cookies. (Optional)',
    #    os.path.expandvars('/tmp/ebay-$USER-cookie')
    #)

    reg_variable('DEBUG', 'Print stacktraces and write ghostdriver.log', type=bool, value=0)
    reg_variable('LOGIN_URL', 'URL for ebay login page', 'https://signin.ebay.de/ws/eBayISAPI.dll?SignIn')
    reg_variable('LOGIN_URL_RE', 'RegEx to check if URL is a login page', 'https://signin.ebay.de')
    reg_variable('LOGIN_FIELD_PASS_RE', 'RegEx to find password input field in login page', 'passwor')
    reg_variable('LOGIN_FIELD_USER_RE', 'RegEx to find user input field in login page', 'e-mail')
项目:kibitzr    作者:kibitzr    | 项目源码 | 文件源码
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]
项目:albert-heijn-calendar-sync    作者:StefanPahlplatz    | 项目源码 | 文件源码
def __init__(self):
        """
        Initializes a web client and logs the user in.
        """
        with open('settings.yaml') as s:
            settings = yaml.load(s)
        print('Initializing web driver...')
        if settings['showbrowser']:
            self.driver = webdriver.Firefox(executable_path=settings['geckopath'])
        else:
            if settings['phantomjspath']:
                self.driver = webdriver.PhantomJS(executable_path=settings['phantomjspath'])
            else:
                self.driver = webdriver.PhantomJS()
        print('Logging in...')
        self.__login()
        print('Loading the schedule...')
        self.__load_schedule()
项目:picoCTF    作者:picoCTF    | 项目源码 | 文件源码
def setup_class(self):
        start_xvfb()
        self.driver = webdriver.Firefox()
        self.test_user = register_test_user(self.driver)
项目:picoCTF    作者:picoCTF    | 项目源码 | 文件源码
def setup_class(self):
        start_xvfb()
        self.driver = webdriver.Firefox()
        self.test_user = register_test_user(self.driver)
项目:OpenCouture-Dev    作者:9-9-0    | 项目源码 | 文件源码
def finalBossSEL(self):
        driver = webdriver.Firefox()
        driver.get(self.URL_pay_url)
        driver.add_cookie(self.user_session.cookies)
项目:OpenCouture-Dev    作者:9-9-0    | 项目源码 | 文件源码
def __init__(self):
        self.br = mechanize.Browser()
        #self.cj = cookielib.LWPCookieJar()
        self.cj = cookielib.MozillaCookieJar()

        self.br.set_cookiejar(self.cj)
        self.br.set_handle_equiv(True)
        self.br.set_handle_referer(True)
        self.br.set_handle_robots(False)
        self.br.addheaders = [('User-agent', 'Firefox')]

        self.item_url = 'http://shop.bdgastore.com/collections/footwear/products/y-3-pureboost-zg'

        # Create variables for user credentials and a function to import them
项目:OpenCouture-Dev    作者:9-9-0    | 项目源码 | 文件源码
def checkCart(self):
        print self.cj

        #driver = webdriver.Firefox()
        #driver.add_cookie(cj_dict)
        #driver.get('http://shop.bdgastore.com/cart')
        #print(driver.get_cookies())
        #for cookie in self.cj:
        #    print cookie.name, cookie.value, cookie.domain
        #try importing cookies manually vs using the requests util

        #driver = webdriver.Chrome('./chromedriver')
项目:DorkNet    作者:NullArray    | 项目源码 | 文件源码
def proxy(PROXY_HOST,PROXY_PORT):
    fp = webdriver.FirefoxProfile()
    print "[" + t.green("+") + "]Proxy host set to: " + PROXY_HOST
    print "[" + t.green("+") + "]Proxy port set to: " + PROXY_PORT
    print "\n[" + t.green("+") + "]Establishing connection..."
    fp.set_preference("network.proxy.type", 1)
    fp.set_preference("network.proxy.http",PROXY_HOST)
    fp.set_preference("network.proxy.http_port",int(PROXY_PORT))
    fp.set_preference("general.useragent.override","'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36'")
    fp.update_preferences()
    return webdriver.Firefox(firefox_profile=fp)


# Function to generate and process results based on input
项目:NewsScrapy    作者:yinzishao    | 项目源码 | 文件源码
def __init__(self):
        self.display = Display(visible=0, size=(800, 600))  #???????
        self.display.start()
        # self.chromedriver = "/home/youmi/Downloads/chromedriver"
        # self.driver = webdriver.Chrome(self.chromedriver)              #??display???????
        chromedriver = "/home/ubuntu/geckodriver"
        self.driver = webdriver.Firefox(executable_path=chromedriver)
项目:NewsScrapy    作者:yinzishao    | 项目源码 | 文件源码
def parse_news(self,response):
        # driver = webdriver.Chrome(self.chromedriver)
        driver = webdriver.Firefox(executable_path=self.chromedriver)
        item = response.meta.get("item",NewsItem())
        page = response.meta.get("page",1)
        index = response.meta.get("index",0)
        origin_url = response.url
        no_res = re.search(r"/(\d+)?.html",origin_url)
        news_no = no_res.group(1) if no_res else None
        driver.get(origin_url)
        time.sleep(3)
        code = driver.page_source
        driver.quit()
        soup = BeautifulSoup(code,"lxml")
        # import pdb;pdb.set_trace()
        authors = soup("span",class_="author-name")
        referer_web = None
        for a in authors:
            if "??".decode("utf-8") in a.text:
                referer_web = a.text[3:]
        news_date = soup.find("span",class_="article-time").text if soup.find("span",class_="article-time") else None
        content = soup.find("div",id="article_content").get_text(strip=True) if soup.find("div",id="article_content") else None
        item["content"]=content
        item["news_date"]=news_date
        item["referer_web"]=referer_web
        item["crawl_date"]=NOW
        item["news_no"]=news_no
        item =judge_news_crawl(item,end_day=2)
        if item:
            yield item
        else:
            self.flag=page

        #??????????????????????
        if index == 19 and not self.flag:
            next_page = page+1
            next_page_url = self.next_page_url % next_page
            yield scrapy.Request(next_page,meta={"page":next_page})
项目:NewsScrapy    作者:yinzishao    | 项目源码 | 文件源码
def __init__(self):
        self.display = Display(visible=0, size=(800, 600))  #???????
        self.display.start()
        # chromedriver = "/home/youmi/Downloads/chromedriver"
        # self.driver = webdriver.Chrome(chromedriver)                   #??display???????
        chromedriver = "/home/ubuntu/geckodriver"
        self.driver = webdriver.Firefox(executable_path=chromedriver)
项目:ScatterFly    作者:nikshepsvn    | 项目源码 | 文件源码
def get_browser():
        browser = input("Are you using Chrome or Firefox? -- Enter C for Chrome, F for Firefox. Press X to exit.")
        if browser == 'F':
            return("Firefox")
        elif browser == 'C':
            return("Chrome")
        elif browser == 'X':
            sys.exit(1)
            return("Exit")
        else:
            return("Invalid")

#function that obtains data from browser
项目:Tktr    作者:Intuity    | 项目源码 | 文件源码
def make_browser(cls):
        # Build a selenium browser
        try:
            cls.browser = webdriver.PhantomJS()
        except Exception:
            try:
                # Fall back to Firefox
                cls.browser = webdriver.Firefox()
            except:
                raise Exception("Could not start a Firefox or PhantomJS instance!")
        cls.browser.get("http://127.0.0.1:%i/" % cls.port_num)
        # Setup to support routing
        cls.app = cls._make_app()
项目:integration    作者:mendersoftware    | 项目源码 | 文件源码
def firefox_driver():
    # Doesn't work with geckodriver! :(
    capabilities = webdriver.DesiredCapabilities().FIREFOX
    capabilities['acceptSslCerts'] = True

    profile = webdriver.FirefoxProfile()
    profile.accept_untrusted_certs = True

    return webdriver.Firefox(firefox_profile=profile, capabilities=capabilities)
项目:MediumBot    作者:MattFlood7    | 项目源码 | 文件源码
def Launch():
    """
    Launch the Medium bot and ask the user what browser they want to use.
    """

    if 'chrome' not in DRIVER.lower() and 'firefox' not in DRIVER.lower() and 'phantomjs' not in DRIVER.lower():

        # Browser choice
        print 'Choose your browser:'
        print '[1] Chrome'
        print '[2] Firefox/Iceweasel'
        print '[3] PhantomJS'

        while True:
            try:
                browserChoice = int(raw_input('Choice? '))
            except ValueError:
                print 'Invalid choice.',
            else:
                if browserChoice not in [1,2,3]:
                    print 'Invalid choice.',
                else:
                    break

        StartBrowser(browserChoice)

    elif 'chrome' in DRIVER.lower():
        StartBrowser(1)

    elif 'firefox' in DRIVER.lower():
        StartBrowser(2)

    elif 'phantomjs' in DRIVER.lower():
        StartBrowser(3)
项目:MediumBot    作者:MattFlood7    | 项目源码 | 文件源码
def StartBrowser(browserChoice):
    """
    Based on the option selected by the user start the selenium browser.
    browserChoice: browser option selected by the user.
    """

    if browserChoice == 1:
        print '\nLaunching Chrome'
        browser = webdriver.Chrome()
    elif browserChoice == 2:
        print '\nLaunching Firefox/Iceweasel'
        browser = webdriver.Firefox()
    elif browserChoice == 3:
        print '\nLaunching PhantomJS'
        browser = webdriver.PhantomJS()

    if SignInToService(browser):
        print 'Success!\n'
        MediumBot(browser)

    else:
        soup = BeautifulSoup(browser.page_source, "lxml")
        if soup.find('div', {'class':'alert error'}):
            print 'Error! Please verify your username and password.'
        elif browser.title == '403: Forbidden':
            print 'Medium is momentarily unavailable. Please wait a moment, then try again.'
        else:
            print 'Please make sure your config is set up correctly.'

    browser.quit()
项目:picoCTF    作者:royragsdale    | 项目源码 | 文件源码
def setup_class(self):
        start_xvfb()
        self.driver = webdriver.Firefox()
        self.test_user = register_test_user(self.driver)
项目:picoCTF    作者:royragsdale    | 项目源码 | 文件源码
def setup_class(self):
        start_xvfb()
        self.driver = webdriver.Firefox()
        self.test_user = register_test_user(self.driver)
项目:spread-knowledge-repository    作者:danieldev13    | 项目源码 | 文件源码
def __init__(self):
        """
        For firefox web driver's sake, we need to point to the location of the browser's installation.
        We, then can pass that in the firefox_binary variable to the Firefox web driver parameter.
        """
        binary = FirefoxBinary(settings.web_browser_location)
        self.driver = webdriver.Firefox(firefox_binary=binary)
项目:Shodita    作者:Quantika14    | 项目源码 | 文件源码
def screenShot(ImageFolder,IP):
    ''' 
        Metodo para hacer el screenshot con selenium haciendo la conexion
        a la web en caso sea posible esa conexion.
    '''


    print '[INFO] Trying to connect to:',str(IP)
    IP = str(IP)
    if 'http' not in IP:
        aux = 'http://'+IP 
    #ahora conectar y screenshot
    try:
        if not ImageFolder.endswith('/'):
            nombreScreenShot = ImageFolder+'/'+IP+'.png'
        else:
            nombreScreenShot = ImageFolder+IP+'.png'
        client = MongoClient()
        db = client.test
        db.Nobisuke.insert({"IP":str(IP),"Picture":str(nombreScreenShot),"bot":"Nobisuke Nobi"})
        driver = webdriver.Firefox()
        driver.get(aux)
        driver.save_screenshot(nombreScreenShot)
        driver.quit()
    except Exception as e:
        print '[-] ERROR TRYING SCREENSHOT: (%s) %s'%(IP,e)
项目:Software-Architecture-with-Python    作者:PacktPublishing    | 项目源码 | 文件源码
def setup():
    driver = webdriver.Firefox()    
    yield driver
    driver.quit()
项目:PythonStudyCode    作者:TongTongX    | 项目源码 | 文件源码
def accessToken(self):
        browser = webdriver.Firefox()
        browser.get("https://developers.facebook.com/tools/explorer")
项目:PythonStudyCode    作者:TongTongX    | 项目源码 | 文件源码
def login(self):
        browser = webdriver.Firefox()
        browser.get("https://www.facebook.com")
        browser.find_element_by_id('email').send_keys(self.username)
        browser.find_element_by_id('pass').send_keys(self.password)
        browser.find_element_by_id('u_0_n').click()
项目:devsecops-example-helloworld    作者:boozallen    | 项目源码 | 文件源码
def __init__(self, driver, event_listener):
        """
        Creates a new instance of the EventFiringWebDriver

        :Args:
         - driver : A WebDriver instance
         - event_listener : Instance of a class that subclasses AbstractEventListener and implements it fully or partially

        Example:

        .. code-block:: python

            from selenium.webdriver import Firefox
            from selenium.webdriver.support.events import EventFiringWebDriver, AbstractEventListener

            class MyListener(AbstractEventListener):
                def before_navigate_to(self, url, driver):
                    print("Before navigate to %s" % url)
                def after_navigate_to(self, url, driver):
                    print("After navigate to %s" % url)

            driver = Firefox()
            ef_driver = EventFiringWebDriver(driver, MyListener())
            ef_driver.get("http://www.google.co.in/")
        """
        if not isinstance(driver, WebDriver):
            raise WebDriverException("A WebDriver instance must be supplied")
        if not isinstance(event_listener, AbstractEventListener):
            raise WebDriverException("Event listener must be a subclass of AbstractEventListener")
        self._driver = driver
        self._driver._wrap_value = self._wrap_value
        self._listener = event_listener
项目:FunUtils    作者:HoussemCharf    | 项目源码 | 文件源码
def Launch():
    # Check if the file 'config' exists, otherwise quit
    if os.path.isfile('config') == False:
        print ('Error! No configuration file.')
        sys.exit()
    # Check if the file 'visitedUsers.txt' exists, otherwise create it
    if os.path.isfile('visitedUsers.txt') == False:
        visitedUsersFile = open('visitedUsers.txt', 'wb')
        visitedUsersFile.close()

    # Browser choice
    print ('Choose your browser:')
    print ('[1] Chrome')
    print ('[2] Firefox/Iceweasel')
    print ('[3] Firefox/Iceweasel (light)')
    print ('[4] PhantomJS')
    print ('[5] PhantomJS (light)')

    while True:
        try:
            browserChoice = int(input('Choice? '))
        except ValueError:
            print ('Invalid choice.')
        else:
            if browserChoice not in [1,2,3,4,5]:
                print ('Invalid choice.')
            else:
                break

    StartBrowser(browserChoice)
项目:xfinity-usage    作者:jantman    | 项目源码 | 文件源码
def get_browser(self):
        """get a webdriver browser instance """
        if self.browser_name == 'firefox':
            logger.debug("getting Firefox browser (local)")
            if 'DISPLAY' not in os.environ:
                logger.debug("exporting DISPLAY=:0")
                os.environ['DISPLAY'] = ":0"
            browser = webdriver.Firefox()
        elif self.browser_name == 'chrome':
            logger.debug("getting Chrome browser (local)")
            browser = webdriver.Chrome()
        elif self.browser_name == 'chrome-headless':
            logger.debug('getting Chrome browser (local) with --headless')
            chrome_options = Options()
            chrome_options.add_argument("--headless")
            browser = webdriver.Chrome(chrome_options=chrome_options)
        elif self.browser_name == 'phantomjs':
            logger.debug("getting PhantomJS browser (local)")
            dcap = dict(DesiredCapabilities.PHANTOMJS)
            dcap["phantomjs.page.settings.userAgent"] = self.user_agent
            args = [
                '--ssl-protocol=any',
                '--ignore-ssl-errors=true',
                '--web-security=false'
            ]
            browser = webdriver.PhantomJS(
                desired_capabilities=dcap, service_args=args
            )
        else:
            raise SystemExit(
                "ERROR: browser type must be one of 'firefox', 'chrome', "
                "'phantomjs', or 'chrome-headless' not '{b}'".format(
                    b=self.browser_name
                )
            )
        browser.set_window_size(1024, 768)
        logger.debug("returning browser")
        return browser