本文整理汇总了Python中selenium.webdriver.common.desired_capabilities.DesiredCapabilities.PHANTOMJS属性的典型用法代码示例。如果您正苦于以下问题:Python DesiredCapabilities.PHANTOMJS属性的具体用法?Python DesiredCapabilities.PHANTOMJS怎么用?Python DesiredCapabilities.PHANTOMJS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类selenium.webdriver.common.desired_capabilities.DesiredCapabilities
的用法示例。
在下文中一共展示了DesiredCapabilities.PHANTOMJS属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createHeadlessBrowser
# 需要导入模块: from selenium.webdriver.common.desired_capabilities import DesiredCapabilities [as 别名]
# 或者: from selenium.webdriver.common.desired_capabilities.DesiredCapabilities import PHANTOMJS [as 别名]
def createHeadlessBrowser(proxy=None, XResolution=1024, YResolution=768, timeout=20):
#proxy = None
if TEST_MODE == False:
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.86 Safari/537.36')
# Fake browser headers
if proxy != None:
# This means the user set a proxy
service_args = ['--proxy={}'.format(proxy),'--proxy-type=https','--ignore-ssl-errors=true', '--ssl-protocol=any', '--web-security=false',]
driver = webdriver.PhantomJS(service_args=service_args, desired_capabilities=dcap)
else:
# No proxy was set by the user
driver = webdriver.PhantomJS(desired_capabilities=dcap)
driver.set_window_size(XResolution,YResolution)
# Sets the screen resolution
# Ideally this will be dynamic based on the number of browsers open
driver.set_page_load_timeout(timeout)
# Sets the timeout for the selenium window
else:
driver = webdriver.Firefox()
return driver
# Returns driver instance
示例2: setup_phantomjs
# 需要导入模块: from selenium.webdriver.common.desired_capabilities import DesiredCapabilities [as 别名]
# 或者: from selenium.webdriver.common.desired_capabilities.DesiredCapabilities import PHANTOMJS [as 别名]
def setup_phantomjs():
"""Create and return a PhantomJS browser object."""
try:
# Setup capabilities for the PhantomJS browser
phantomjs_capabilities = DesiredCapabilities.PHANTOMJS
# Some basic creds to use against an HTTP Basic Auth prompt
phantomjs_capabilities['phantomjs.page.settings.userName'] = 'none'
phantomjs_capabilities['phantomjs.page.settings.password'] = 'none'
# Flags to ignore SSL problems and get screenshots
service_args = []
service_args.append('--ignore-ssl-errors=true')
service_args.append('--web-security=no')
service_args.append('--ssl-protocol=any')
# Create the PhantomJS browser and set the window size
browser = webdriver.PhantomJS(desired_capabilities=phantomjs_capabilities,service_args=service_args)
browser.set_window_size(1920,1080)
except Exception as error:
click.secho("[!] Bad news: PhantomJS failed to load (not installed?), so activities \
requiring a web browser will be skipped.",fg="red")
click.secho("L.. Details: {}".format(error),fg="red")
browser = None
return browser
示例3: test_create_local_driver_phantomjs
# 需要导入模块: from selenium.webdriver.common.desired_capabilities import DesiredCapabilities [as 别名]
# 或者: from selenium.webdriver.common.desired_capabilities.DesiredCapabilities import PHANTOMJS [as 别名]
def test_create_local_driver_phantomjs(webdriver_mock, config):
config.set('Driver', 'type', 'phantomjs')
config.set('Driver', 'phantomjs_driver_path', '/tmp/driver')
config_driver = ConfigDriver(config)
config_driver._create_local_driver()
webdriver_mock.PhantomJS.assert_called_once_with(desired_capabilities=DesiredCapabilities.PHANTOMJS,
executable_path='/tmp/driver')
示例4: test_create_remote_driver_phantomjs
# 需要导入模块: from selenium.webdriver.common.desired_capabilities import DesiredCapabilities [as 别名]
# 或者: from selenium.webdriver.common.desired_capabilities.DesiredCapabilities import PHANTOMJS [as 别名]
def test_create_remote_driver_phantomjs(webdriver_mock, config):
config.set('Driver', 'type', 'phantomjs')
server_url = 'http://10.20.30.40:5555'
utils = mock.MagicMock()
utils.get_server_url.return_value = server_url
config_driver = ConfigDriver(config, utils)
config_driver._create_remote_driver()
webdriver_mock.Remote.assert_called_once_with(command_executor='%s/wd/hub' % server_url,
desired_capabilities=DesiredCapabilities.PHANTOMJS)
示例5: _get_PhantomJS
# 需要导入模块: from selenium.webdriver.common.desired_capabilities import DesiredCapabilities [as 别名]
# 或者: from selenium.webdriver.common.desired_capabilities.DesiredCapabilities import PHANTOMJS [as 别名]
def _get_PhantomJS(self):
try:
service_args = []
if self.proxy:
service_args.extend([
'--proxy={}:{}'.format(self.proxy.host, self.proxy.port),
'--proxy-type={}'.format(self.proxy.proto),
])
if self.proxy.username and self.proxy.password:
service_args.append(
'--proxy-auth={}:{}'.format(
self.proxy.username,
self.proxy.password
)
)
useragent = random_user_agent(
mobile=False
)
logger.info('useragent: {}'.format(useragent))
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = useragent
try:
self.webdriver = webdriver.PhantomJS(
executable_path=self.config['executable_path'],
service_args=service_args,
desired_capabilities=dcap
)
return True
except (ConnectionError, ConnectionRefusedError, ConnectionResetError) as err:
logger.error(err)
return False
except WebDriverException as e:
logger.error(e)
return False
示例6: host_worker
# 需要导入模块: from selenium.webdriver.common.desired_capabilities import DesiredCapabilities [as 别名]
# 或者: from selenium.webdriver.common.desired_capabilities.DesiredCapabilities import PHANTOMJS [as 别名]
def host_worker(hostQueue, fileQueue, timeout, user_agent, verbose):
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = user_agent
dcap["accept_untrusted_certs"] = True
driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true'], desired_capabilities=dcap) # or add to your PATH
driver.set_window_size(1024, 768) # optional
driver.set_page_load_timeout(timeout)
while(not hostQueue.empty()):
host = hostQueue.get()
if not host.startswith("http://") and not host.startswith("https://"):
host1 = "http://" + host
host2 = "https://" + host
filename1 = os.path.join("output", "images", str(uuid4()) + ".png")
filename2 = os.path.join("output", "images", str(uuid4()) + ".png")
if verbose:
print("Fetching %s" % host1)
if host_reachable(host1, timeout) and save_image(host1, filename1, driver):
fileQueue.put({host1: filename1})
else:
if verbose:
print("%s is unreachable or timed out" % host1)
if verbose:
print("Fetching %s" % host2)
if host_reachable(host2, timeout) and save_image(host2, filename2, driver):
fileQueue.put({host2: filename2})
else:
if verbose:
print("%s is unreachable or timed out" % host2)
else:
filename = os.path.join("output", "images", str(uuid4()) + ".png")
if verbose:
print("Fetching %s" % host)
if host_reachable(host, timeout) and save_image(host, filename, driver):
fileQueue.put({host: filename})
else:
if verbose:
print("%s is unreachable or timed out" % host)
示例7: get
# 需要导入模块: from selenium.webdriver.common.desired_capabilities import DesiredCapabilities [as 别名]
# 或者: from selenium.webdriver.common.desired_capabilities.DesiredCapabilities import PHANTOMJS [as 别名]
def get(driver_path):
if not os.path.exists(driver_path):
raise FileNotFoundError("Could not find phantomjs executable at %s. Download it for your platform at http://phantomjs.org/download.html", driver_path)
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = IPHONE_UA
driver = webdriver.PhantomJS(desired_capabilities=dcap, executable_path=driver_path)
driver.set_window_size(1024, 3000)
return driver
示例8: get_pages
# 需要导入模块: from selenium.webdriver.common.desired_capabilities import DesiredCapabilities [as 别名]
# 或者: from selenium.webdriver.common.desired_capabilities.DesiredCapabilities import PHANTOMJS [as 别名]
def get_pages(self):
'''
通过Phantomjs获得网页完整源码,解析出每一页漫画的url
Get all pages' urls using selenium an phantomJS
return:
a list of tuple (page_num,page_url)
'''
r_slt=r'onchange="select_page\(\)">([\s\S]*?)</select>'
r_p=r'<option value="(.*?)".*?>第(\d*?)页<'
try:
dcap = dict(DesiredCapabilities.PHANTOMJS)
# 不载入图片,爬页面速度会快很多
dcap["phantomjs.page.settings.loadImages"] = False
driver = webdriver.PhantomJS(desired_capabilities=dcap)
driver.get(self.chapter_url)
text=driver.page_source
st=re.findall(r_slt,text)[0]
self.pages = [(int(p[-1]),p[0]) for p in re.findall(r_p,st)]
except Exception:
traceback.print_exc()
self.pages = []
except KeyboardInterrupt:
raise KeyboardInterrupt
finally:
driver.quit()
print('Got {l} pages in chapter {ch}'.format(l=len(self.pages),ch=self.chapter_title))
return self.pages