本文整理汇总了Python中pyvirtualdisplay.Display方法的典型用法代码示例。如果您正苦于以下问题:Python pyvirtualdisplay.Display方法的具体用法?Python pyvirtualdisplay.Display怎么用?Python pyvirtualdisplay.Display使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvirtualdisplay
的用法示例。
在下文中一共展示了pyvirtualdisplay.Display方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_screenshot
# 需要导入模块: import pyvirtualdisplay [as 别名]
# 或者: from pyvirtualdisplay import Display [as 别名]
def save_screenshot(self, main_url, screenshot_path):
try:
from pyvirtualdisplay import Display
display = Display(visible=0, size=(1024, 768))
display.start()
from selenium import webdriver
try:
if '127.0.0.1' in main_url or 'localhost' in main_url:
br = webdriver.Firefox()
else:
from selenium.webdriver.common.proxy import Proxy, ProxyType
proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'httpProxy': HTTP_PROXY
})
br = webdriver.Firefox(proxy=proxy)
except Exception, e:
LOG.exception(e)
br = webdriver.Firefox()
br.get(main_url)
br.save_screenshot(screenshot_path)
br.quit()
display.stop()
return screenshot_path
示例2: create_display
# 需要导入模块: import pyvirtualdisplay [as 别名]
# 或者: from pyvirtualdisplay import Display [as 别名]
def create_display():
"""
Create a virtual display
Default size is 1920x1080 as smaller resolution
may cause problem in firefox
"""
status = True
if data_Utils.get_object_from_datarepository("headless_display"):
return status
try:
from pyvirtualdisplay import Display
# Selenium has problem with firefox in virtualdisplay if resolution is low
display = Display(visible=0, size=(1920, 1080))
display.start()
print_info("Running in headless mode")
except ImportError:
print_error("pyvirtualdisplay is not installed in order "
"to launch the browser in headless mode")
status = False
except Exception as err:
print_error("Encountered Exception: {0}, while trying to launch the browser"
" in headless mode".format(err))
status = False
return status
示例3: setUpClass
# 需要导入模块: import pyvirtualdisplay [as 别名]
# 或者: from pyvirtualdisplay import Display [as 别名]
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()
示例4: pollute_forever
# 需要导入模块: import pyvirtualdisplay [as 别名]
# 或者: from pyvirtualdisplay import Display [as 别名]
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(f'.pollute() exception:\n{e}')
示例5: crawl_setup
# 需要导入模块: import pyvirtualdisplay [as 别名]
# 或者: from pyvirtualdisplay import Display [as 别名]
def crawl_setup(tor=False, capture_path="", display_mode=0, port="9000", process_tag="1", exits="US"):
tor_call = ""
make_folder(capture_path)
if tor is True:
profile_ = setup_profile(tor=True, port=port, firebug=True, netexport=True, noscript=False,
capture_path=capture_path)
torrc_file = create_tor_config(port, "./torrc-" + process_tag, exits)
tor_call = start_program("/usr/sbin/tor -f " + torrc_file)
else:
profile_ = setup_profile(firebug=True, netexport=True, noscript=False, capture_path=capture_path)
display_ = Display(visible=0, size=(1024, 768))
if display_mode == 0:
display_.start()
binary = FirefoxBinary("./firefox/firefox")
driver_ = webdriver.Firefox(firefox_profile=profile_, firefox_binary=binary)
driver_.set_page_load_timeout(60)
driver_.set_script_timeout(60)
return driver_, display_, tor_call
示例6: start_search
# 需要导入模块: import pyvirtualdisplay [as 别名]
# 或者: from pyvirtualdisplay import Display [as 别名]
def start_search(self):
for socket in self.sockets:
with Display():
try:
self.search(socket)
except Exception as e:
print('%s: %s' % (type(e).__name__, str(e)))
print('trying next socket...')
finally:
self.browser.quit()
self.request_count += 1
if self.request_count > self.request_MAX:
self.request_count = 0
self.scrape_sockets()
示例7: start
# 需要导入模块: import pyvirtualdisplay [as 别名]
# 或者: from pyvirtualdisplay import Display [as 别名]
def start(self):
self._virtual_display = pyvirtualdisplay.Display(
backend='xvfb', size=(self.width, self.height),
color_depth=self.colordepth, use_xauth=self.xauth,
extra_args=self.args)
self._virtual_display.start()
self.display = self._virtual_display.display
assert self._virtual_display.is_alive()
示例8: __init__
# 需要导入模块: import pyvirtualdisplay [as 别名]
# 或者: from pyvirtualdisplay import Display [as 别名]
def __init__(self,showbrowser):
display = Display(visible=0, size=(1600, 1024))
display.start()
if not showbrowser:
os.environ['MOZ_HEADLESS'] = '1'
firefoxprofile = webdriver.FirefoxProfile()
firefoxprofile.set_preference("permissions.default.desktop-notification", 1)
firefoxprofile.set_preference("dom.webnotifications.enabled", 1)
firefoxprofile.set_preference("dom.push.enabled", 1)
self.driver = webdriver.Firefox(firefox_profile=firefoxprofile)
self.driver.implicitly_wait(15)
self.driver.delete_all_cookies()
示例9: __init__
# 需要导入模块: import pyvirtualdisplay [as 别名]
# 或者: from pyvirtualdisplay import Display [as 别名]
def __init__(self,showbrowser):
display = Display(visible=0, size=(1600, 1024))
display.start()
if not showbrowser:
os.environ['MOZ_HEADLESS'] = '1'
firefoxprofile = webdriver.FirefoxProfile()
firefoxprofile.set_preference("permissions.default.desktop-notification", 1)
firefoxprofile.set_preference("dom.webnotifications.enabled", 1)
firefoxprofile.set_preference("dom.push.enabled", 1)
self.driver = webdriver.Firefox(firefox_profile=firefoxprofile)
self.driver.implicitly_wait(15)
#self.driver.delete_all_cookies()
示例10: init_driver_headless
# 需要导入模块: import pyvirtualdisplay [as 别名]
# 或者: from pyvirtualdisplay import Display [as 别名]
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
示例11: start_display
# 需要导入模块: import pyvirtualdisplay [as 别名]
# 或者: from pyvirtualdisplay import Display [as 别名]
def start_display():
""" Starts a virtual display
"""
global DISPLAY
display_info = get_config_value('display')
logging.getLogger("easyprocess").setLevel(logging.INFO)
w = int(display_info['width']) + 100
h = int(display_info['height']) + 100
DISPLAY = Display(visible=0, size=(w,h))
DISPLAY.start()
time.sleep(2)
BuiltIn().log('Started a virtual display as `%s`' % DISPLAY.new_display_var)
示例12: screenshot
# 需要导入模块: import pyvirtualdisplay [as 别名]
# 或者: from pyvirtualdisplay import Display [as 别名]
def screenshot(file_path):
BuiltIn().log("WRN: This keyword is deprecated. Use `Display Capture` instead",console=True)
capture_display(file_path)
示例13: start_xvfb
# 需要导入模块: import pyvirtualdisplay [as 别名]
# 或者: from pyvirtualdisplay import Display [as 别名]
def start_xvfb(win_width=cm.DEFAULT_XVFB_WIN_W,
win_height=cm.DEFAULT_XVFB_WIN_H):
xvfb_display = Display(visible=0, size=(win_width, win_height))
xvfb_display.start()
return xvfb_display
示例14: setUpClass
# 需要导入模块: import pyvirtualdisplay [as 别名]
# 或者: from pyvirtualdisplay import Display [as 别名]
def setUpClass(cls):
super(SeleniumTestCase, cls).setUpClass()
if settings.SKIP_SELENIUM_TESTS:
return
if settings.VIRTUAL_DISPLAY:
cls.vdisplay = Display(visible=0, size=(1024, 768))
cls.vdisplay.start()
cls.selenium = WebDriver(
executable_path=settings.GECKODRIVER_PATH,
service_log_path=settings.GECKODRIVER_LOG_PATH
)
cls.selenium.implicitly_wait(10)
示例15: get_odds_checker_odds
# 需要导入模块: import pyvirtualdisplay [as 别名]
# 或者: from pyvirtualdisplay import Display [as 别名]
def get_odds_checker_odds(match, league='premier-league'):
home_team_name = constants.FLASH_SCORES_TEAM_TO_ODDS_CHECKER[match['home_team']]
away_team_name = constants.FLASH_SCORES_TEAM_TO_ODDS_CHECKER[match['away_team']]
odds_url = 'https://www.oddschecker.com/football/english/{}/{}-v-{}/winner'.format(league, home_team_name, away_team_name)
display = Display(visible=0, size=(1024, 768))
display.start()
driver = webdriver.Firefox('/usr/local/bin/')
driver.get(odds_url)
time.sleep(10)
html_source = driver.page_source
driver.quit()
display.stop()
soup = BeautifulSoup(html_source, 'lxml')
home_team_for_soup = deslugify(home_team_name)
away_team_for_soup = deslugify(away_team_name)
if home_team_for_soup == 'Cardiff City':
home_team_for_soup = 'Cardiff City'
if away_team_for_soup == 'Cardiff City':
away_team_for_soup = 'Cardiff City'
home = soup.find('tr', {'data-bname': home_team_for_soup})
draw = soup.find('tr', {'data-bname': 'Draw'})
away = soup.find('tr', {'data-bname': away_team_for_soup})
home_bookies = home.get('data-best-bks')
home_odds = float(home.get('data-best-dig'))
draw_bookies = draw.get('data-best-bks')
draw_odds = float(draw.get('data-best-dig'))
away_bookies = away.get('data-best-bks')
away_odds = float(away.get('data-best-dig'))
return [home_bookies, draw_bookies, away_bookies], [1 / home_odds, 1 / draw_odds, 1 / away_odds]