Python selenium.webdriver.common.desired_capabilities.DesiredCapabilities.PHANTOMJS Examples
The following are 8
code examples of selenium.webdriver.common.desired_capabilities.DesiredCapabilities.PHANTOMJS().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
selenium.webdriver.common.desired_capabilities.DesiredCapabilities
, or try the search function
.
Example #1
Source File: main.py From SneakerBotTutorials with MIT License | 6 votes |
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
Example #2
Source File: helpers.py From ODIN with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #3
Source File: test_config_driver.py From toolium with Apache License 2.0 | 5 votes |
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')
Example #4
Source File: test_config_driver.py From toolium with Apache License 2.0 | 5 votes |
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)
Example #5
Source File: selenium.py From SerpScrap with MIT License | 5 votes |
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
Example #6
Source File: snapper.py From Snapper with GNU General Public License v2.0 | 5 votes |
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)
Example #7
Source File: phantomjs.py From the-endorser with MIT License | 5 votes |
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
Example #8
Source File: comic.py From ComicSpider with GNU General Public License v3.0 | 5 votes |
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