本文整理汇总了Python中selenium.webdriver.chrome.options.Options.set_headless方法的典型用法代码示例。如果您正苦于以下问题:Python Options.set_headless方法的具体用法?Python Options.set_headless怎么用?Python Options.set_headless使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.chrome.options.Options
的用法示例。
在下文中一共展示了Options.set_headless方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: take
# 需要导入模块: from selenium.webdriver.chrome.options import Options [as 别名]
# 或者: from selenium.webdriver.chrome.options.Options import set_headless [as 别名]
def take(self, location: Location) -> str:
"""
Take a screenshot using chrome webdriver.
Args:
location: The location of the map's center point.
Returns:
The screenshot's full path.
"""
context: Context = {
"key": self.api_key,
"latitude": location.latitude,
"longitude": location.longitude,
"zoom": location.zoom,
}
map_html = os.path.join(self._tmpdir, "map.html")
render_template(os.path.join(self._template_dir, "map.j2"), context, map_html)
options = Options()
options.set_headless(headless=True)
driver = webdriver.Chrome(
executable_path=self.webdriver_path, chrome_options=options
)
driver.set_window_size(self.width, self.height)
driver.get("file://%s" % map_html)
time.sleep(5)
self.path = os.path.join(self.output_dir, "map.png")
driver.save_screenshot(self.path)
driver.quit()
return self.path
示例2: startMobileDriver
# 需要导入模块: from selenium.webdriver.chrome.options import Options [as 别名]
# 或者: from selenium.webdriver.chrome.options.Options import set_headless [as 别名]
def startMobileDriver(self):
chrome_mobile_opts = Options()
chrome_mobile_opts.add_argument('disable-infobars')
chrome_mobile_opts.add_argument('disable-search-geolocation-disclosure')
chrome_mobile_opts.set_headless(self.useHeadless)
if self.mobileUA != None:
chrome_mobile_opts.add_argument("user-agent=" + self.mobileUA)
if self.loadDefaultProfile == True:
chrome_mobile_opts.add_argument("user-data-dir=" + self.chromedirect)
self.chromeMobileDriver = webdriver.Chrome(executable_path=self.webDriver, chrome_options=chrome_mobile_opts)
self.mobileRunning = True
if self.loadCookies == True and self.cookies != None:
# Loading cookies only works if we are at a site the cookie would work for
self.getMobileUrl("https://login.live.com")
self.chromeMobileDriver.delete_all_cookies()
for cookie in self.cookies:
# print("Adding cookie to Chrome Mobile Driver: %s" % str(cookie))
# new_cookie = {}
# new_cookie['name'] = cookie['name']
# new_cookie['value'] = cookie['value']
try:
self.chromeMobileDriver.add_cookie(cookie)
except selenium.common.exceptions.InvalidCookieDomainException:
continue
示例3: start
# 需要导入模块: from selenium.webdriver.chrome.options import Options [as 别名]
# 或者: from selenium.webdriver.chrome.options.Options import set_headless [as 别名]
def start(self):
if self.engine == 'chrome':
from selenium.webdriver.chrome.options import Options
options = Options()
options.set_headless(headless=True)
options.add_argument('--disable-gpu')
options.add_argument('--log-level=3')
options.add_argument('--mute-audio')
options.add_experimental_option('prefs', {
'profile.managed_default_content_settings.images': 2,
})
options.binary_location = self.binary_path
driver = webdriver.Chrome(
chrome_options=options,
executable_path=self.driver_path,
)
elif self.engine == 'firefox':
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.options import Options
options = Options()
options.set_headless(headless=True)
options.add_argument('--disable-gpu')
profile = webdriver.FirefoxProfile()
profile.set_preference('permissions.default.image', 2)
profile.set_preference('media.volume_scale', '0.0')
profile.set_preference('media.autoplay.enabled', False)
binary = FirefoxBinary(self.binary_path)
driver = webdriver.Firefox(
firefox_profile=profile,
firefox_options=options,
firefox_binary=binary,
executable_path=self.driver_path,
log_file=os.devnull,
)
driver.set_window_size(1920, 1080)
self.driver = driver