當前位置: 首頁>>代碼示例>>Python>>正文


Python DesiredCapabilities.PHANTOMJS屬性代碼示例

本文整理匯總了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 
開發者ID:theriley106,項目名稱:SneakerBotTutorials,代碼行數:25,代碼來源:main.py

示例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 
開發者ID:chrismaddalena,項目名稱:ODIN,代碼行數:24,代碼來源:helpers.py

示例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') 
開發者ID:Telefonica,項目名稱:toolium,代碼行數:10,代碼來源:test_config_driver.py

示例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) 
開發者ID:Telefonica,項目名稱:toolium,代碼行數:12,代碼來源:test_config_driver.py

示例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 
開發者ID:ecoron,項目名稱:SerpScrap,代碼行數:39,代碼來源:selenium.py

示例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) 
開發者ID:dxa4481,項目名稱:Snapper,代碼行數:39,代碼來源:snapper.py

示例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 
開發者ID:eth0izzle,項目名稱:the-endorser,代碼行數:13,代碼來源:phantomjs.py

示例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 
開發者ID:QuantumLiu,項目名稱:ComicSpider,代碼行數:29,代碼來源:comic.py


注:本文中的selenium.webdriver.common.desired_capabilities.DesiredCapabilities.PHANTOMJS屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。