python类Display()的实例源码

low_level.py 文件源码 项目:Trading212-API 作者: federico123579 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def launch(self):
        """launch browser and virtual display, first of all to be launched"""
        try:
            # init virtual Display
            self.vbro = Display()
            self.vbro.start()
            logger.debug("virtual display launched")
        except Exception:
            raise exceptions.VBroException()
        try:
            self.browser = Browser(self.brow_name)
            logger.debug(f"browser {self.brow_name} launched")
        except Exception:
            raise exceptions.BrowserException(
                self.brow_name, "failed to launch")
        return True
download facebook photos.py 文件源码 项目:Facebook-Photos-Download-Bot 作者: NalinG 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
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."
funcselenium.py 文件源码 项目:django-functest 作者: django-functest 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        if not cls.display_browser_window():
            display_args = {'visible': False}
            if cls.browser_window_size is not None:
                # For some browsers, we need display to be bigger
                # than the size we want the window to be.
                width, height = cls.browser_window_size
                display_args['size'] = (width + 500, height + 500)
            cls.__display = Display(**display_args)
            cls.__display.start()

        # We have one driver attached to the class, re-used between test runs
        # for speed. Manually started driver instances (using new_browser_session)
        # are cleaned up at the end of an individual test.
        cls._cls_driver = cls._create_browser_instance()
        super(FuncSeleniumMixin, cls).setUpClass()
isp_data_pollution.py 文件源码 项目:isp-data-pollution 作者: essandess 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def pollute_forever(self):
        if self.verbose: print("""Display format:
Downloading: website.com; NNNNN links [in library], H(domain)= B bits [entropy]
Downloaded:  website.com: +LLL/NNNNN links [added], H(domain)= B bits [entropy]
""")
        self.open_driver()
        self.seed_links()
        self.clear_driver()
        if self.quit_driver_every_call: self.quit_driver()
        while True: # pollute forever, pausing only to meet the bandwidth requirement
            try:
                if (not self.diurnal_flag) or self.diurnal_cycle_test():
                    self.pollute()
                else:
                    time.sleep(self.chi2_mean_std(3.,1.))
                if npr.uniform() < 0.005: self.set_user_agent()  # reset the user agent occasionally
                self.elapsed_time = time.time() - self.start_time
                self.exceeded_bandwidth_tasks()
                self.random_interval_tasks()
                self.every_hour_tasks()
                time.sleep(self.chi2_mean_std(0.5,0.2))
            except Exception as e:
                if self.debug: print('.pollute() exception:\n{}'.format(e))
WebDriverUtil.py 文件源码 项目:webnuke 作者: bugbound 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def getDriverWithProxySupport(self, proxy_host, proxy_port):
        if self.debug == False:
            self.display = Display(visible=0, size=(1920, 1080))
            self.display.start()
        profile = self.getWebDriverProfile()
        profile.set_preference("network.proxy.type", 1)
        profile.set_preference("network.proxy.http", proxy_host)
        profile.set_preference("network.proxy.http_port", proxy_port)
        profile.set_preference("network.proxy.https", proxy_host)
        profile.set_preference("network.proxy.https_port", proxy_port)
        profile.set_preference("network.proxy.ssl", proxy_host)
        profile.set_preference("network.proxy.ssl_port", proxy_port)
        profile.update_preferences()

        capabilities = webdriver.DesiredCapabilities().FIREFOX
        capabilities["marionette"] = False
        newdriver = webdriver.Firefox(firefox_profile=profile, capabilities=capabilities)

        #newdriver = webdriver.Firefox(firefox_profile=profile)
        self.wait = ui.WebDriverWait(newdriver, 10) # timeout after 10 seconds
        return newdriver
gmail.py 文件源码 项目:tools 作者: okabe 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__( self, bid, sleep_time, threshold, printq ):

        self.bid = bid
        self.sleep_time = sleep_time
        self.threshold = threshold
        self.emails = []
        self.passwords = []
        self.printq = printq
        self.count = 0
        self.finished = False

        self.display = Display( visible=0, size=( 1280, 800 ) )
        self.display.start()

        self.browser = webdriver.Firefox()
        self.printq.put( "[>] Initialized browser {}".format( str( self.bid ) ) )
fromSE.py 文件源码 项目:Book_DeepLearning_Practice 作者: wac81 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_ans_from_zd_webdriver(question):
    """
    ??????????????????????
    :param question:
    :return:
    """
    global zhidaoHeader
    global ZHIDAO

    # invisualble
    # display = Display(visible=0, size=(800, 600))
    # display.start()

    url_q_list = ZHIDAO + "/index?rn=10&word=" + question
    driver = webdriver.Firefox()
    driver.get(url_q_list)
    content = driver.find_element_by_xpath('/html/body/div[3]/p[1]/a')

    return None
cb_spider.py 文件源码 项目:NewsScrapy 作者: yinzishao 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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)
yicai_spider.py 文件源码 项目:NewsScrapy 作者: yinzishao 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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)
browser.py 文件源码 项目:wazo-admin-ui 作者: wazo-pbx 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, username, password, virtual=True):
        self.username = username
        self.password = password
        self.display = Display(visible=virtual, size=(1024, 768))
Crawler.py 文件源码 项目:APKCrawler 作者: Hyunsik-Yoo 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def __init__(self, is_desktop):
        """
        ???
        is_desktop : ?????? ??????, ??????(GUI)?? ??????\
                     (true, false)
        """
        # config.ini??? ?? ????
        config = configparser.ConfigParser()
        config.read('config.ini')
        self.apk_directory = config.get('Setting','APK_DIRECTORY')
        self.is_desktop = is_desktop

        # ????? ?????? ??????? ??
        if(not is_desktop):
            self.display = Display(visible=0, size=(800, 600))
            self.display.start()

        # ?? ???? ?? 
        self.chrome = webdriver.Chrome(config.get('Setting',\
            'CHROME_DRIVER_DIRECTORY'))

        # ???? ???? ??? ??
        self.category_list = config.items('PlayStoreURL')

        # ???? ???? ??? DBController?? ??
        self.db_connector = DBController(config.get('Setting','DB_DIRECTORY'))

        # ?????? ??? SQLite ??? ??
        self.db_connector.create_table()
test_selenium.py 文件源码 项目:varapp-backend-py 作者: varapp 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        cls.display = Display(visible=0, size=(1600, 1200))
        cls.display.start()
        cls.driver = webdriver.Firefox()
        #cls.driver = webdriver.Chrome()   # requires chromedriver in path and pip installed
        #cls.driver = webdriver.PhantomJS()
web.py 文件源码 项目:mf-platform-bse 作者: utkarshohm 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def init_driver_headless():
    '''
    Initialize headless browser. it needs a virtual display
    '''
    from pyvirtualdisplay import Display
    global Display  # global variable because its needed in quit_driver()
    display = Display(visible = 0, size = (1024, 768))
    display.start()
    print "display initialized for headless browser"

    driver = webdriver.Firefox()
    return driver
headlessBrowser.py 文件源码 项目:crawler_sqlmap 作者: CvvT 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, **kwargs):
        self.display = Display(visible=0, size=(800, 600))
        self.display.start()

        self._experiment = False
        self._depth = -1
        # signal
        self.onfinish = Finish()

        super(HeadlessBrowser, self).__init__(**kwargs)
order.py 文件源码 项目:pi-order 作者: dyej 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, username, password, url):
        self.username = username
        self.password = password
        self.url = url
        self.display = Display(visible=0, size=(1920, 1080))
        self.display.start()
        self.browser = webdriver.Chrome()
        self.browser.implicitly_wait(15)
get_links.py 文件源码 项目:Malicious_Domain_Whois 作者: h-j-13 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_final_url(url):
    with Display(backend="xvfb", size=(1440, 900)):
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get(url)
        url = driver.current_url
        driver.quit()
        return url
proximus_auto_add_vol_pack.py 文件源码 项目:proximus_auto_add_vol_pack 作者: salcin 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def set_debug(self):

        if self.debug == 'yes':
            value = 1
        else:
            value = 0       # not display window browser

        self.display = Display(visible=value, size=(1440, 900)).start()
browser.py 文件源码 项目:biweeklybudget 作者: jantman 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def display(self):
        display = getattr(self, "_display", None)
        if display is None:
            # http://coreygoldberg.blogspot.com/2011/06/python-headless-selenium-webdriver.html
            display = Display(visible=0, size=(800, 600))
            display.start()
            self._display = display
        return display
crawler_selenium.py 文件源码 项目:django-radar 作者: chairco 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _driver(self):
        if self.virtual:
            self.display = Display(visible=0, size=(1024, 786))
            self.display.start()

        service_args = [
        '--webdriver-loglevel=ERROR'  # only record ERROR message
        '--proxy=127.0.0.1:3128',
        ]

        # setting Chrome option
        os.environ['webdriver.chrome.driver'] = self.driver_path
        prefs = {'download.default_directory': self.download_path_temp}
        proxy = '127.0.0.1:3128'

        chrome_options = Options()
        chrome_options.add_experimental_option('prefs', prefs)
        chrome_options.add_argument('--proxy-server=http://%s' % proxy)

        driver = webdriver.Chrome(
            executable_path=self.driver_path, # ?? dirver ??
            service_log_path=self.logs_path, # ?? log ????
            chrome_options=chrome_options, # ????????
            #service_args=service_args,
        )
        return driver
CJODocIDSpider_wo_scrapy_new.py 文件源码 项目:fintech_spider 作者: hee0624 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def get_chrome_driver(self):
        display = None
        driver = None
        try:
            options = webdriver.ChromeOptions()
            proxy = get_proxy()
            if proxy:
                options.add_argument('--proxy-server=' + proxy)
            else:
                return None    # proxy is essential
            display = Display(visible=0, size=(800, 800))
            display.start()
            driver = webdriver.Chrome(executable_path=r"/home/lxw/Software/chromedriver_selenium/chromedriver", chrome_options=options)

            # ??????
            driver.set_page_load_timeout(self.TIMEOUT)
            driver.set_script_timeout(self.TIMEOUT)  # ???????????
        except Exception as e:
            self.error_logger.error("lxw get_chrome_driver() Exception: {0}\n{1}\n\n".format(e, "--"*30))
            if display:
                display.stop()
            if driver:
                driver.quit()
            return None, None
        else:
            return display, driver
CJOSpider_wo_scrapy_new.py 文件源码 项目:fintech_spider 作者: hee0624 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_chrome_driver(self):
        # chromedriver
        display = None
        driver = None
        try:
            options = webdriver.ChromeOptions()
            proxy = get_proxy()
            if proxy:
                options.add_argument('--proxy-server=' + proxy)
            else:
                return None    # proxy is essential
            display = Display(visible=0, size=(800, 800))
            display.start()
            driver = webdriver.Chrome(executable_path=r"/home/lxw/Software/chromedriver_selenium/chromedriver", chrome_options=options)

            # ??????
            driver.set_page_load_timeout(self.TIMEOUT)
            driver.set_script_timeout(self.TIMEOUT)  # ???????????
        except Exception as e:
            self.error_logger.error("lxw get_chrome_driver() Exception: {0}\n{1}\n{2}\n\n".format(e, traceback.format_exc(), "--"*30))
            if display:
                display.stop()
            if driver:
                driver.quit()
            return None, None
        else:
            return display, driver
new_cjo_spider_test.py 文件源码 项目:fintech_spider 作者: hee0624 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_driver_chrome(self):
        # chromedriver
        options = webdriver.ChromeOptions()
        proxy = get_proxy()
        # NOTE: ??"http"?"https"??????????http?????https
        self.proxies["http"] = proxy
        self.proxies["https"] = proxy
        if proxy:
            options.add_argument('--proxy-server=' + proxy)

        display = Display(visible=0, size=(800, 800))
        display.start()
        driver = webdriver.Chrome(executable_path=r"/home/lxw/Software/chromedriver_selenium/chromedriver", chrome_options=options)

        """
        # PhantomJS: Not working. why?
        driver = webdriver.PhantomJS(executable_path=r"/home/lxw/Downloads/phantomjs/phantomjs-2.1.1-linux-x86_64/bin/phantomjs")
        proxy = webdriver.Proxy()
        proxy.proxy_type = ProxyType.MANUAL
        proxy_str = get_proxy()
        if proxy_str:
            proxy.http_proxy = proxy_str
        # ????????webdriver.DesiredCapabilities.PHANTOMJS?
        proxy.add_to_capabilities(webdriver.DesiredCapabilities.PHANTOMJS)
        driver.start_session(webdriver.DesiredCapabilities.PHANTOMJS)
        """

        # ??????
        driver.set_page_load_timeout(self.TIMEOUT)
        driver.set_script_timeout(self.TIMEOUT)  # ???????????
        return driver
selenium_display.py 文件源码 项目:fintech_spider 作者: hee0624 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_driver_chrome():
    # chromedriver
    options = webdriver.ChromeOptions()

    # display = Display(visible=1, size=(800, 800))
    display = Display(visible=0, size=(800, 800))
    display.start()
    driver = webdriver.Chrome(executable_path=r"/home/lxw/Software/chromedriver_selenium/chromedriver",
                              chrome_options=options)

    # ??????
    driver.set_page_load_timeout(60)
    driver.set_script_timeout(60)  # ???????????
    return display, driver
test_integration.py 文件源码 项目:django-rest-messaging-centrifugo 作者: raphaelgyory 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        super(IntegrationTests, cls).setUpClass()
        # we do not display
        cls.display = Display(visible=0, size=(1024, 768))
        cls.display.start()
        cls.selenium = WebDriver()
        # we create a user
        password = "password"
        cls.user = User(username="UserForLiveTests")
        cls.user.set_password(password)
        cls.user.save()
        # we log him in
        # source http://stackoverflow.com/questions/22494583/login-with-code-when-using-liveservertestcase-with-django
        # we need a session
        session = SessionStore()
        session[SESSION_KEY] = cls.user.id
        session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0]
        session[HASH_SESSION_KEY] = cls.user.get_session_auth_hash()
        session.save()
        # the cookie dict
        cls.cookie = {
            'name': settings.SESSION_COOKIE_NAME,
            'value': session.session_key,
            'secure': False,
            'path': '/',
        }
        # we launch centrifugo
        cls.centrifugo = subprocess.Popen(["centrifugo --config=tests/config.json --port={0}".format(getattr(settings, "CENTRIFUGO_PORT", 8802))], stdout=subprocess.PIPE,
                                          shell=True, preexec_fn=os.setsid)
        # we create participants
        cls.participant1 = Participant.objects.create(id=cls.user.id)
        cls.participant2 = Participant.objects.create(id=2)
        cls.participant3 = Participant.objects.create(id=3)
        cls.participant4 = Participant.objects.create(id=4)
        # we create a fake request
        cls.request = RequestFactory()
        cls.request.rest_messaging_participant = cls.participant1
        # and wait for it to run
        time.sleep(4)
utils.py 文件源码 项目:line_bot_server 作者: NCKU-CCS 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def get_web_screenshot(web_info):
    logger.info('Getting zapper web screenshot and uploading......\n')
    display = Display(visible=0)
    display.start()

    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--no-sandbox')
    browser = webdriver.Chrome(executable_path=settings.CHROME_DRIVER_PATH, chrome_options=chrome_options)
    browser.set_window_size(web_info['width'], web_info['height'])
    browser.implicitly_wait(10)
    browser.get(web_info['url'])

    sleep(1)
    img_base64 = browser.get_screenshot_as_base64()
    browser.close()
    display.stop()

    # upload to imgur.com
    response = requests.request(
        "POST", url=IMGUR_API_URL, data=img_base64,
        headers={'authorization': 'Client-ID {client_id}'.format(client_id=settings.IMGUR_CLIENT_ID)}
    )
    response_json = response.json()

    if response.status_code == 200:
        return response_json['data']['link']
    else:
        logger.warning(
            ('ImgurApiError\n'
             'Status Code: %s\n'
             'Error Message: %s\n'),
            response.status_code, response_json['data']['error']
        )
        return False
east_money_utils.py 文件源码 项目:BlackCoffee 作者: IMYin 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def simulate_web():
    display = Display(visible=0, size=(800, 600))
    display.start()
    driver = webdriver.Chrome(cons.CHROME_PATH)
    return driver
fakepic.py 文件源码 项目:real-senate-floor 作者: buzzfeed-openlab 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _screenshot_tweet(self):
        outfile = '%s/output/%s/screenshot.png' % (dir_path, self.tweet_id)
        if not os.path.isfile('%s/output/%s/screenshot.png' % (dir_path, self.tweet_id)):
            print("    fakepic: screenshotting tweet")

            if USE_VIRTUAL_DISPLAY:
                display = Display(visible=0, size=(1920, 600))
                display.start()

            driver = webdriver.Firefox()
            driver.get(self.tweet_url)
            driver.save_screenshot(outfile)
            driver.quit()
sogou_weixin.py 文件源码 项目:sogou_weixin 作者: xiaodaguan 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def create_display(self):
        self.client_sys_info = platform.platform().lower()
        if self.client_sys_info.find("windows") == -1:
            self.display = Display(visible=0, size=(1280, 1024))
            self.display.start()
            self.logger.info("display started.")
utils.py 文件源码 项目:luzfcb_dj_simplelock 作者: luzfcb 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        super(SplinterStaticLiveServerTestCase, cls).setUpClass()
        if cls.use_virtual_display:
            cls.virtual_display = Display(visible=0, size=cls.virtual_display_size)
            cls.virtual_display.start()
        cls.browser = Browser(cls.splinter_driver)
        cls.browser.driver.maximize_window()
downloaders.py 文件源码 项目:wechat-spider 作者: bowenpay 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def get_display(self):
        """ ?????????? """
        if platform.system() != 'Darwin':
            # ??mac??, ????
            display = Display(visible=0, size=(1024, 768))
            display.start()
        else:
            display = None
        return display


问题


面经


文章

微信
公众号

扫码关注公众号