def loginToInterface(isMac, chrome, driver, host, port=8686, username='******', password='******'): logCommon.info('Will start web browser and perform test case.') chromeDriver = os.path.normpath(driver) logCommon.info('Browser driver path: ' + str(chromeDriver)) os.environ["webdriver.chrome.driver"] = chromeDriver opts = Options() if (not isMac): opts = Options() opts.binary_location = os.path.normpath(chrome) else: opts.add_argument("--start-maximized") driver = webdriver.Chrome(chromeDriver, chrome_options=opts) # options.add_argument("--start-maximized") # driver.set_window_size(1024, 600) driver.maximize_window() # go to the google home page index = 'http://' + str(host) + ':' + str(port) + '/XOAM/login/index.html' logCommon.info('Web page: ' + str(index)) driver.get(index) driver.find_element_by_id('loginUsername').clear() driver.find_element_by_id('loginUsername').send_keys(username) driver.find_element_by_id('loginPassword').clear() driver.find_element_by_id('loginPassword').send_keys(password) driver.find_element_by_id('submit').click() try: WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "ebBtnSearch"))) logCommon.info('Login to the InterfaceManagement page successfully.') except Exception as e: logCommon.error('Login to the InterfaceManagement page failed.') return False return driver
def makeConnection(SERVER, USER, PASSWORD): url = 'https://'+SERVER+'/' chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.binary_location = '/usr/bin/chromium-browser' driver = webdriver.Chrome(executable_path= os.path.expanduser('~/usr/local/bin/chromedriver') , chrome_options=chrome_options) driver.get(url) time.sleep(1) driver.save_screenshot(os.path.join(os.path.dirname(os.path.realpath(__file__)), '/tmp', 'kk1.png')) elemU = driver.find_element_by_name("username") #while elemU: print("Identifying...") elemP = driver.find_element_by_name("password") elemU.clear() elemU.send_keys(USER) elemP.clear() elemP.send_keys(PASSWORD) driver.save_screenshot(os.path.join(os.path.dirname(os.path.realpath(__file__)), '/tmp', 'kk2.png')) elemP.send_keys(Keys.RETURN) time.sleep(1) # try: # elemU = driver.find_element_by_name("username").clear() # except: # elemU = None driver.save_screenshot(os.path.join(os.path.dirname(os.path.realpath(__file__)), '/tmp', 'kk3.png')) return driver
def launch_browser(): if env.RUNNING_BROWSER.upper() == "FIREFOX": # the end of the browser process , the end of the browser driven process os.popen("TASKKILL /F /IM firefoxdriver.exe") fp = FirefoxProfile() fp.native_events_enabled = False binary_path = PublicImp.common.get_value_from_conf("FIREFOX_BINARY_PATH") if binary_path == "": env.driver = selenium.webdriver.Firefox(firefox_profile=fp) else: fb = FirefoxBinary(firefox_path=binary_path) env.driver = selenium.webdriver.Firefox(firefox_profile=fp, firefox_binary=fb) elif env.RUNNING_BROWSER.upper() == "CHROME": os.popen("TASKKILL /F /IM chromedriver.exe") binary_path = PublicImp.common.get_value_from_conf("CHROME_BINARY_PATH") chromedriver = PublicImp.common.get_value_from_conf("DRIVER_CHROME") if binary_path == "": os.environ["webdriver.chrome.driver"] = chromedriver env.driver = selenium.webdriver.Chrome(executable_path=chromedriver) else: opts = Options() opts.binary_location = binary_path os.environ["webdriver.chrome.driver"] = chromedriver env.driver = selenium.webdriver.Chrome(executable_path=chromedriver, chrome_options=opts) elif env.RUNNING_BROWSER.upper() == "IE": os.popen("TASKKILL /F /IM IEDriverServer.exe") dc = DesiredCapabilities.INTERNETEXPLORER.copy() dc['acceptSslCerts'] = True dc['nativeEvents'] = True iedriver = PublicImp.common.get_value_from_conf("DRIVER_IE") os.environ["webdriver.ie.driver"] = iedriver env.driver = selenium.webdriver.Ie(executable_path=iedriver, capabilities=dc) else: return False env.platformName = env.RUNNING_BROWSER env.TEST_URL = PublicImp.common.get_value_from_conf("TESTING_URL") env.driver.get(env.TEST_URL) env.driver.maximize_window() time.sleep(3) env.driver.refresh() # env.driver.set_window_size(480, 800) time.sleep(3) return True
def launch_webdriver(self): options = Options() options.binary_location = '' options.debugger_address = '{}:{}'.format( DEFAULT_WEBVIEW_INSPECTOR_IP, DEFAULT_WEBVIEW_INSPECTOR_PORT) self.driver = webdriver.Chrome( executable_path=CHROMEDRIVER_EXEC_PATH, chrome_options=options) self.assertThat(self.driver, NotEquals(None))
def setUpClass(cls): if not os.path.isfile(PATH_TO_CHROME): raise Exception("No Chrome binary at '" + PATH_TO_CHROME + "'. " "Set PATH_TO_CHROME.") if not os.path.isfile(PATH_TO_CHROMEDRIVER): raise Exception("No Chrome Driver binary at '" + PATH_TO_CHROMEDRIVER + "'." "Set PATH_TO_CHROMEDRIVER.") options = Options() options.binary_location = PATH_TO_CHROME FormClassificationTest.driver = webdriver.Chrome(PATH_TO_CHROMEDRIVER, chrome_options=options)
def __init__(self, chrome_path, chromedriver_path, profile_path, passwords_path, enable_automatic_password_saving): """Creates a new testing Environment, starts Chromedriver. Args: chrome_path: The chrome binary file. chromedriver_path: The chromedriver binary file. profile_path: The chrome testing profile folder. passwords_path: The usernames and passwords file. enable_automatic_password_saving: If True, the passwords are going to be saved without showing the prompt. Raises: IOError: When the passwords file cannot be accessed. ParseError: When the passwords file cannot be parsed. Exception: An exception is raised if |profile_path| folder could not be removed. """ # Cleaning the chrome testing profile folder. if os.path.exists(profile_path): shutil.rmtree(profile_path) options = Options() if enable_automatic_password_saving: options.add_argument("enable-automatic-password-saving") # TODO(vabr): show_prompt is used in WebsiteTest for asserting that # Chrome set-up corresponds to the test type. Remove that knowledge # about Environment from the WebsiteTest. self.show_prompt = not enable_automatic_password_saving options.binary_location = chrome_path options.add_argument("user-data-dir=%s" % profile_path) # The webdriver. It's possible to choose the port the service is going to # run on. If it's left to 0, a free port will be found. self.driver = webdriver.Chrome(chromedriver_path, 0, options) # Password internals page tab/window handle. self.internals_window = self.driver.current_window_handle # An xml tree filled with logins and passwords. self.passwords_tree = ElementTree.parse(passwords_path).getroot() self.website_window = self._OpenNewTab() self.websitetests = [] # Map messages to the number of their appearance in the log. self.message_count = { MESSAGE_ASK: 0, MESSAGE_SAVE: 0 } # A list of (test_name, test_type, test_success, failure_log). self.tests_results = []
def get_chrome_driver(self): """Setup and return a Chrom[e|ium] browser for Selenium.""" opts = Options() absp = os.path.abspath if "TRAVIS" in os.environ: # github.com/travis-ci/travis-ci/issues/938 opts.add_argument("--no-sandbox") opts.add_extension(self.pb_ext_path) # will fail if ext can't be found if self.browser_bin: # otherwise will use webdriver's default binary print "Browser binary:", absp(self.browser_bin) opts.binary_location = self.browser_bin # set binary location # Fix for https://code.google.com/p/chromedriver/issues/detail?id=799 opts.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"]) return webdriver.Chrome(chrome_options=opts)
def get_a_chrome_headless_driver(): from selenium.webdriver.chrome.options import Options CHROME_PATH = '/usr/bin/google-chrome-stable' CHROMEDRIVER_PATH = '/home/user/bin/chromedriver' WINDOW_SIZE = "1920,1080" opts = Options() opts.add_argument("--headless") opts.add_argument("--window-size=%s" % WINDOW_SIZE) opts.binary_location = CHROME_PATH driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, chrome_options=opts) return driver
def before_all(context): benv.before_all(context) context.screenshots_dir = os.environ.get('SANITYSCREENSHOTDIR') context.default_browser = os.environ.get('SANITYBROWSER', '') if context.default_browser.lower() == 'chrome_headless': context.default_browser = 'chrome' options = Options() options.binary_location = '/usr/bin/google-chrome' options.add_argument('--headless') options.add_argument('--disable-gpu') context.browser_args = { 'options': options, } context.base_url = get_base_url(os.environ['SANITYURL'])
def create(url): options = Options() options.binary_location = CHROME options.add_argument('--headless') options.add_argument('--disable-gpu') options.add_argument('--ignore-certificate-errors') options.add_argument('--allow-running-insecure-content') options.add_argument('--disable-web-security') options.add_argument('--lang=ja') options.add_argument('--blink-settings=imagesEnabled=false') driver = webdriver.Chrome(chrome_options=options) driver.get(url) driver_wait = WebDriverWait(driver, 10) driver_wait.until(ec.presence_of_all_elements_located) return driver
def chrome_manager(self): opts = Options() if self.on_travis: # github.com/travis-ci/travis-ci/issues/938 opts.add_argument("--no-sandbox") opts.add_extension(self.extension_path) opts.binary_location = self.browser_path opts.add_experimental_option("prefs", {"profile.block_third_party_cookies": False}) caps = DesiredCapabilities.CHROME.copy() driver = webdriver.Chrome(chrome_options=opts, desired_capabilities=caps) try: yield driver finally: driver.quit()
def _get_driver(self, user_data_dir, profile_name=None, chrome_binary=None, chromedriver_binary='chromedriver'): """Spin up a ChromeDriver instance that uses a given set of user data. Generates a temporary profile data directory using a local set of test data. Args: user_data_dir: Path string for the writable directory in which profiles should be stored. profile_name: Name of the profile data directory to be created/used in user_data_dir. If None then an eight character name will be generated randomly. This directory will be removed after the task flow completes. chrome_binary: Path string to the Chrome binary that should be used by ChromeDriver. If None then it will use the PATH to find a binary. Returns: The generated Chrome Driver instance. """ options = Options() if profile_name is None: profile_name = ''.join(choice(ascii_lowercase) for i in range(8)) options.add_argument('--profile-directory=%s' % profile_name) full_path = os.path.realpath(__file__) path, filename = os.path.split(full_path) profile_dir_src = os.path.join(path, 'testdata', 'Default') self._profile_dir_dst = os.path.join(user_data_dir, profile_name) self._copy_tree(profile_dir_src, self._profile_dir_dst) if chrome_binary is not None: options.binary_location = chrome_binary options.add_argument('--user-data-dir=%s' % user_data_dir) options.add_argument('--show-autofill-type-predictions') service_args = [] driver = webdriver.Chrome(executable_path=chromedriver_binary, chrome_options=options, service_args=service_args) driver.set_page_load_timeout(15) # seconds return driver
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
def add_options(self, chromiumlike, cache_state): ''' Sets a bunch of cmd switches and options passed to selenium''' mode = "chromiumlike" if chromiumlike else "sparrow" driver_options = Options() # Field Trial if chromiumlike: driver_options.add_argument('--sparrow-force-fieldtrial=chromiumlike') driver_options.add_argument('--user-agent=%s' % self.user_agent) driver_options.add_argument('--user-data-dir=%s' % self.chromiumlike_user_data_dir) else: driver_options.add_argument('--sparrow-force-fieldtrial') driver_options.add_argument('--user-data-dir=%s' % self.sparrow_user_data_dir) for switch in self.sparrow_only_switches: driver_options.add_argument(switch) logging.debug("Adding switch to sparrow only: %s" % switch) # Passed from config file for switch in self.common_switches: driver_options.add_argument(switch) logging.debug("Adding switch: %s" % switch) if self.ublock_path: if not os.path.exists(self.ublock_path): print("Error, ublock crx file not found.") sys.exit(1) driver_options.add_extension(self.ublock_path) # Test label test_label_entry = "--beer-test-label=%s-%s-%s-%s-%s-%s" % (self.test_label_prefix, self.chromium_version, sys.platform, mode, cache_state, self.test_start_time) driver_options.add_argument(test_label_entry) logging.info(test_label_entry) driver_options.binary_location = self.binary_location driver_options.to_capabilities()['loggingPrefs'] = { 'browser':'ALL' } return driver_options
def parse(self, response): opts = Options() opts.binary_location = '/usr/bin/chromium-browser' driver = webdriver.Chrome(chrome_options=opts) driver.get('http://www.google.com') jsonresponse = json.loads(response.body_as_unicode()) pages = jsonresponse["list"]["pagination"] total_count = jsonresponse["list"]["binCounts"]["totalResultCount"] print total_count print pages pages_html = fromstring(pages) pages = pages_html.xpath('//li/a/@href') print len(pages) page_url = pages[0] print page_url import sys
def windows_chrome_login_rsnms(browser_path, driver_path, host, username, password, port, url): """ init selenium driver for chrome on windows platform. :param browser_path: chrome installation path :param driver_path: selenium path :param host: host ip of target rsnms server :param username: username that to login to the rsnms server :param password: password that to login to the rsnms server :param port: port number of target url :return: the driver instance of the selenium """ chrome_driver = os.path.normpath(driver_path) test.info('Browser driver path: ' + str(chrome_driver)) os.environ["webdriver.chrome.driver"] = chrome_driver opts = Options() opts.binary_location = os.path.normpath(browser_path) test.info('Browser path: ' + str(browser_path)) driver = webdriver.Chrome(chrome_driver, chrome_options=opts) # driver.set_window_size(1024, 600) driver.maximize_window() login_first_page(driver, host, username, password, port, url) return driver
def open_browser(self,url): """Opens the cef instance and the provide url""" chrome_driver_path = self.chrome_driver_location() c_o = Options() c_o.add_argument("--disable-web-security") #redirect webdriver output to null, this doesn't block the pipe #and stops a chromium freeze c_o.add_argument("--webdriver-logfile=%s" % os.devnull) #don't let chromium go to http://www.google.com, instead #point it to the landing page c_o.add_argument("--url=%s" % url) #custom browser location c_o.binary_location = self.cef_location() #redirect logs to null file service_args = ["--log-path=%s" % os.devnull] self.browser = webdriver.Chrome(executable_path=chrome_driver_path, chrome_options=c_o, service_args=service_args) self.browser.get(url) #wait for a recipe to be choosen elem = WebDriverWait( self.browser, 1000 ).until( EC.presence_of_element_located( (By.ID, "make_recipe")) ) inputs = None try: inputs=json.loads(self.browser.find_element_by_id("make_recipe_input").get_attribute("value")) except Exception as e: print e #load the recipe, this contains all the steps #and other config params tut_config = json.load( open( os.path.join(basedir, elem.get_attribute("value") ) ) ) #run a tutorial self.run_tut(tut_config["steps"], tut_config["metadata"], inputs)
def __init__(self, options=None, chrome_binary=None, chromedriver_binary=None): if options == None: options = Options() options.add_argument('--headless') options.add_argument('--mute-audio') # can really freak you out otherwise options.add_argument('--disable-gpu') options.add_argument('window-size=1280,800') # # try to find the chromedriver binary if chromedriver_binary == None: # look in current directory cur_dir = os.path.dirname(os.path.realpath(__file__)) cur_dir_files = os.listdir(cur_dir) if 'chromedriver' in cur_dir_files: chromedriver_binary = os.path.join(cur_dir, 'chromedriver') elif os.path.isfile('/usr/lib/chromium-browser/chromedriver'): chromedriver_binary = '/usr/lib/chromium-browser/chromedriver' else: chromedriver_binary = shutil.which('chromedriver') # try to find the chrome/chromium binary if chrome_binary == None: chrome_binary = shutil.which('chromium-browser') if not os.path.isfile(chromedriver_binary): raise FileNotFoundError("chromedriver binary not found at {}".format(chromedriver_binary)) if not os.path.isfile(chrome_binary): raise FileNotFoundError("chrome binary not found at {}".format(chrome_binary)) print("creating new chrome instance...") options.binary_location = chrome_binary self._driver = webdriver.Chrome(executable_path=chromedriver_binary, chrome_options=options) self._driverpid = self._driver.service.process.pid
def add_games(user, links): login, password = user options = Options() if chrome_binary_heroku_path: options.binary_location = chrome_binary_heroku_path if hide_browsers: options.add_argument('--window-position=-2000,0') options.add_argument('--headless') options.add_argument('--disable-gpu') root = webdriver.Chrome(executable_path=path, options=options) # Load cookies if drop_box_token: # load dropbox cookies try: root.get('https://www.epicgames.com/id/login') print(f'{login}: Getting cookies from dropbox') cookies_bytes = download(drop_box_token, f'{login}.json') cookies = json.loads(cookies_bytes) for cookie in cookies: try: cookie['expiry'] += 600 # extend cookie except KeyError: pass root.add_cookie(cookie) print(f'{login}: Cookies loaded from dropbox') root.refresh() except ApiError as e: print(f'{login}: {e}') else: # Load local cookies try: root.get('https://www.epicgames.com/id/login') print(f'{login}: Getting cookies from local') with open(f'{login}.json', 'r') as file: cookies = json.load(file) for cookie in cookies: try: cookie['expiry'] += 600 # extend cookie except KeyError: pass root.add_cookie(cookie) print(f'{login}: Cookies loaded') root.refresh() except FileNotFoundError: print(f'{login}: No cookies found') # check if logged in sleep(3) if root.current_url == 'https://www.epicgames.com/id/login': root.get('https://www.epicgames.com/id/login/epic') print(f'{login}: Need to login') if hide_browsers: return False try: WebDriverWait(root, 15).until( EC.presence_of_element_located( (By.ID, 'email'))).send_keys(login) root.find_element_by_id('password').send_keys(password) WebDriverWait(root, 20).until( EC.element_to_be_clickable( (By.CLASS_NAME, 'SubmitButton'))).click() if hide_browsers: root.set_window_position(0, 0) except TimeoutException: print(f'{login}: Failed to login') return False while not root.current_url.startswith( 'https://www.epicgames.com/account/personal'): sleep(2) else: print(f'{login}: already logged in') # save cookies if save_cookies: if drop_box_token: # upload cookies to dropbox cookies = json.dumps(root.get_cookies()) upload(drop_box_token, f'{login}.json', bytes(cookies, encoding='utf-8')) print(f'{login}: Cookies uploaded to dropbox') else: # Save cookies localy with open(f'{user[0]}.json', 'w') as cookies: json.dump(root.get_cookies(), cookies) print(f'{login}: Cookies saved') # loop through links for link, repeating in links: before = len(root.window_handles) root.execute_script('window.open()') while before == len(root.window_handles): sleep(0.1) root.switch_to.window(root.window_handles[-1]) root.get(link) main_div = root.find_elements_by_xpath('//main/*') # remove overlays for i in range(1, len(main_div)): root.execute_script(f""" var element = document.querySelector("main").children[{i}]; if (element) element.parentNode.removeChild(element) """) # get 'GET' buttons from game page root.execute_script("window.scrollTo(0, document.body.scrollHeight);") sleep(5) get_buttons = root.execute_script(""" get_buttons = []; buttons = document.getElementsByTagName('button'); for (button of buttons) {if(button.innerText != undefined && button.innerText.toLowerCase().includes('get')) {get_buttons.push(button)}}; return get_buttons; """) # close if not get buttons if not get_buttons: if not repeating: print(f'{login}: {root.title} already in library') root.execute_script('window.close()') root.switch_to.window(root.window_handles[0]) continue # if more than one get button add link to repeat if not repeating: [links.append((link, 1)) for _ in range(1, len(get_buttons))] # add game to library root.execute_script('arguments[0].click()', get_buttons[0]) sleep(5) success = place_order(root, login) if success: if not repeating: print(f'{login}: {root.title} added to library') else: print(f'{login}: {root.title} DLC added to library') root.execute_script('window.close()') root.switch_to.window(root.window_handles[0]) # close the user profile page root.switch_to.window(root.window_handles[0]) root.close() try: if root.window_handles: if hide_browsers: root.set_window_position(0, 0) while root.window_handles: sleep(15) except: pass return
def _init_chrome_driver(num): chrome_options = Options() if platform.system() == WINDOWS: userdata_path = 'D:\chrome\chromedata{0}'.format(num) cache_path = 'D:\chrome\cache{0}'.format(num) chrome_options.binary_location = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' driver_path = 'C:\Program Files (x86)\chromedriver_win32\chromedriver' chrome_options.add_argument('user-data-dir=' + userdata_path) chrome_options.add_argument('--disk-cache-dir=' + cache_path) preferences_file = os.path.join( userdata_path, 'Default', 'Preferences') elif platform.system() == MAC_OS: userdata_path = '/Users/lllll/coding/chrome/chromedata{0}'.format(num) cache_path = '/Users/lllll/coding/chrome/cache{0}'.format(num) chrome_options.binary_location = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' driver_path = '/usr/local/bin/chromedriver' chrome_options.add_argument('user-data-dir=' + userdata_path) chrome_options.add_argument('--disk-cache-dir=' + cache_path) # chrome_options.add_argument('--headless') # chrome_options.add_argument('--disable-gpu') # chrome_options.add_argument('--start-maximized') # chrome_options.add_argument('--window-size=1200x1000') preferences_file = os.path.join( userdata_path, 'Default', 'Preferences') #selenium_log_file= '/Users/lllll/coding/chrome/logs/selenium.log' elif platform.system() == LINUX: userdata_path = '/data/oak/chrome/chromedata{0}'.format(num) cache_path = '/data/oak/chrome/cache{0}'.format(num) chrome_options.binary_location = '/usr/bin/google-chrome' driver_path = '/usr/bin/chromedriver' chrome_options.add_argument('user-data-dir=' + userdata_path) chrome_options.add_argument('--disk-cache-dir=' + cache_path) # chrome_options.add_argument('--no-sandbox') # chrome_options.add_argument('--headless') # chrome_options.add_argument('--disable-gpu') # chrome_options.add_argument('--window-size=1200x1000') preferences_file = os.path.join( userdata_path, 'Default', 'Preferences') else: print('Unknown OS. Exit') return None drop_content = ['cookies', 'Cookies-journal'] if os.path.exists(preferences_file): os.remove(preferences_file) for content in drop_content: cookie_path = os.path.join(userdata_path, 'Default', content) if os.path.exists(cookie_path): os.remove(cookie_path) # if os.path.exists(cache_path): # shutil.rmtree(cache_path) # os.mkdir(cache_path) # driver = webdriver.Chrome(executable_path=driver_path, chrome_options=chrome_options, service_log_path=selenium_log_file, service_args=["--verbose"]) driver = webdriver.Chrome( executable_path=driver_path, chrome_options=chrome_options) driver.set_page_load_timeout(3 * 60) # driver.delete_all_cookies() return driver
async def carbon_api(e): """ carbon.now.sh için bir çeşit wrapper """ await e.edit("`İşleniyor...`") CARBON = 'https://carbon.now.sh/?l={lang}&code={code}' global CARBONLANG textx = await e.get_reply_message() pcode = e.text if pcode[8:]: pcode = str(pcode[8:]) elif textx: pcode = str(textx.message) # Girilen metin, modüle aktarılıyor. code = quote_plus(pcode) # Çözülmüş url'ye dönüştürülüyor. await e.edit("`İşleniyor...\nTamamlanma Oranı: 25%`") if os.path.isfile("./carbon.png"): os.remove("./carbon.png") url = CARBON.format(code=code, lang=CARBONLANG) chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.binary_location = GOOGLE_CHROME_BIN chrome_options.add_argument("--window-size=1920x1080") chrome_options.add_argument("--disable-dev-shm-usage") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-gpu") prefs = {'download.default_directory': './'} chrome_options.add_experimental_option('prefs', prefs) driver = webdriver.Chrome(executable_path=CHROME_DRIVER, options=chrome_options) driver.get(url) await e.edit("`İşleniyor...\nTamamlanma Oranı: 50%`") download_path = './' driver.command_executor._commands["send_command"] = ( "POST", '/session/$sessionId/chromium/send_command') params = { 'cmd': 'Page.setDownloadBehavior', 'params': { 'behavior': 'allow', 'downloadPath': download_path } } command_result = driver.execute("send_command", params) driver.find_element_by_xpath("//button[contains(text(),'Export')]").click() # driver.find_element_by_xpath("//button[contains(text(),'4x')]").click() # driver.find_element_by_xpath("//button[contains(text(),'PNG')]").click() await e.edit("`İşleniyor...\nTamamlanma Oranı: 75%`") # İndirme için bekleniyor while not os.path.isfile("./carbon.png"): await sleep(0.5) await e.edit("`İşleniyor...\nTamamlanma Oranı: 100%`") file = './carbon.png' await e.edit("`Resim karşıya yükleniyor...`") await e.client.send_file( e.chat_id, file, caption= "Bu resim [Carbon](https://carbon.now.sh/about/) kullanılarak yapıldı,\ \nbir [Dawn Labs](https://dawnlabs.io/) projesi.", force_document=True, reply_to=e.message.reply_to_msg_id, ) os.remove('./carbon.png') driver.quit() # Karşıya yüklemenin ardından carbon.png kaldırılıyor await e.delete() # Mesaj siliniyor
async def carbon_api(e): RED = random.randint(0, 256) GREEN = random.randint(0, 256) BLUE = random.randint(0, 256) OPC = random.random() godboy = await edit_or_reply(e, "⬜⬜⬜⬜⬜") CARBON = "https://carbon.now.sh/?bg=rgba({R}%2C{G}%2C{B}%2C{O})&t=material&wt=none&l=auto&ds=false&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=56px&ph=56px&ln=false&fl=1&fm=Fira%20Code&fs=14px&lh=152%25&si=false&es=2x&wm=false&code={code}" CARBONLANG = "en" textx = await e.get_reply_message() pcode = e.text if pcode[7:]: pcode = str(pcode[7:]) elif textx: pcode = str(textx.message) # Importing message to module code = quote_plus(pcode) # Converting to urlencoded url = CARBON.format(code=code, R=RED, G=GREEN, B=BLUE, O=OPC, lang=CARBONLANG) chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.binary_location = CHROME_BIN # fixed by madboy482 # SAY NO TO KANGS, ELSE GEND FAD DI JAYEGI chrome_options.add_argument("--window-size=1920x1080") chrome_options.add_argument("--disable-dev-shm-usage") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-gpu") prefs = {"download.default_directory": "./"} chrome_options.add_experimental_option("prefs", prefs) await godboy.edit("⬛⬛⬜⬜⬜") driver = webdriver.Chrome(executable_path=Config.CHROME_DRIVER, options=chrome_options) driver.get(url) download_path = "./" driver.command_executor._commands["send_command"] = ( "POST", "/session/$sessionId/chromium/send_command", ) params = { "cmd": "Page.setDownloadBehavior", "params": { "behavior": "allow", "downloadPath": download_path }, } driver.execute("send_command", params) driver.find_element_by_xpath("//button[contains(text(),'Export')]").click() await asyncio.sleep(2) # this might take a bit. # driver.find_element_by_xpath("//button[contains(text(),'4x')]").click() # await asyncio.sleep(5) await godboy.edit("⬛⬛⬛⬜⬜") # driver.find_element_by_xpath("//button[contains(text(),'PNG')]").click() await asyncio.sleep(2) # Waiting for downloading await godboy.edit("⬛⬛⬛⬛⬛") file = "./carbon.png" await godboy.edit("✅RGB Karbon 2.0 Completed, Uploading Karbon✅") await e.client.send_file( e.chat_id, file, caption=f"Here's your karbonrgb", force_document=True, reply_to=e.message.reply_to_msg_id, ) os.remove("./carbon.png") # Removing carbon.png after uploading await godboy.delete() # Deleting msg
Created on 2015年12月6日 @author: LeoBrilliant ''' from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys from selenium.webdriver.chrome.options import Options from time import sleep chrome_exe_dir = r'C:\Users\LeoBrilliant\AppData\Local\360Chrome\Chrome\Application\360chrome.exe' chrome_op = Options() chrome_op.binary_location = chrome_exe_dir browser = webdriver.Chrome(chrome_options=chrome_op) browser.get("http://www.baidu.com") browser.maximize_window() browser.get("http://www.youdao.com") actions = ActionChains(browser) actions.send_keys(Keys.CONTROL, 't').perform() tab1 = browser.current_window_handle
async def carbon_api(e): godboy = await edit_or_reply(e, "`Processing....`") CARBON = "https://carbon.now.sh/?l={lang}&code={code}" textx = await e.get_reply_message() pcode = e.text if pcode[5:]: pcodee = str(pcode[5:]) if "|" in pcodee: pcode, skeme = pcodee.split("|") else: pcode = pcodee skeme = None elif textx: pcode = str(textx.message) skeme = None # Importing message to module pcode = deEmojify(pcode) code = quote_plus(pcode) # Converting to urlencoded await godboy.edit("`Meking Carbon...`\n`25%`") url = CARBON.format(code=code, lang=CARBONLANG) chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.binary_location = CHROME_BIN # fixed by madboy482 # SAY NO TO KANGS, ELSE GEND FAD DI JAYEGI chrome_options.add_argument("--window-size=1920x1080") chrome_options.add_argument("--disable-dev-shm-usage") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-gpu") prefs = {"download.default_directory": "./"} chrome_options.add_experimental_option("prefs", prefs) driver = webdriver.Chrome(executable_path=Config.CHROME_DRIVER, options=chrome_options) driver.get(url) await godboy.edit("`Be Patient...\n50%`") download_path = "./" driver.command_executor._commands["send_command"] = ( "POST", "/session/$sessionId/chromium/send_command", ) params = { "cmd": "Page.setDownloadBehavior", "params": { "behavior": "allow", "downloadPath": download_path }, } driver.execute("send_command", params) driver.find_element_by_xpath( "/html/body/div[1]/main/div[3]/div[2]/div[1]/div[1]/div/span[2]" ).click() if skeme is not None: k_skeme = driver.find_element_by_xpath( "/html/body/div[1]/main/div[3]/div[2]/div[1]/div[1]/div/span[2]/input" ) k_skeme.send_keys(skeme) k_skeme.send_keys(Keys.DOWN) k_skeme.send_keys(Keys.ENTER) else: color_scheme = str(random.randint(1, 29)) driver.find_element_by_id(("downshift-0-item-" + color_scheme)).click() driver.find_element_by_id("export-menu").click() driver.find_element_by_xpath("//button[contains(text(),'4x')]").click() driver.find_element_by_xpath("//button[contains(text(),'PNG')]").click() await godboy.edit("`Processing..\n75%`") # Waiting for downloading await asyncio.sleep(2.5) color_name = driver.find_element_by_xpath( "/html/body/div[1]/main/div[3]/div[2]/div[1]/div[1]/div/span[2]/input" ).get_attribute("value") await godboy.edit("`Done Dana Done...\n100%`") file = "./carbon.png" await godboy.edit("`Uploading..`") await e.client.send_file( e.chat_id, file, caption="`Here's your carbon!` \n**Colour Scheme: **`{}`".format( color_name), force_document=True, reply_to=e.message.reply_to_msg_id, ) os.remove("./carbon.png") driver.quit() await godboy.delete()
async def carbon_api(e): RED = random.randint(0, 256) GREEN = random.randint(0, 256) BLUE = random.randint(0, 256) THEME = [ "3024-night", "a11y-dark", "blackboard", "base16-dark", "base16-light", "cobalt", "dracula", "duotone-dark", "hopscotch", "lucario", "material", "monokai", "night-owl", "nord", "oceanic-next", "one-light", "one-dark", "panda-syntax", "paraiso-dark", "seti", "shades-of-purple", "solarized", "solarized%20light", "synthwave-84", "twilight", "verminal", "vscode", "yeti", "zenburn", ] CUNTHE = random.randint(0, len(THEME) - 1) The = THEME[CUNTHE] if not e.text[0].isalpha() and e.text[0] not in ("/", "#", "@", "!"): """ A Wrapper for carbon.now.sh """ hmm = await e.reply("⬜⬜⬜⬜⬜") CARBON = "https://carbon.now.sh/?bg=rgba({R}%2C{G}%2C{B}%2C1)&t={T}&wt=none&l=auto&ds=false&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=56px&ph=56px&ln=false&fl=1&fm=Fira%20Code&fs=14px&lh=152%25&si=false&es=2x&wm=false&code={code}" CARBONLANG = "en" textx = await e.get_reply_message() pcode = e.text if pcode[8:]: pcode = str(pcode[8:]) elif textx: pcode = str(textx.message) # Importing message to module code = quote_plus(pcode) # Converting to urlencoded url = CARBON.format(code=code, R=RED, G=GREEN, B=BLUE, T=The, lang=CARBONLANG) chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.binary_location = Config.GOOGLE_CHROME_BIN chrome_options.add_argument("--window-size=1920x1080") chrome_options.add_argument("--disable-dev-shm-usage") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-gpu") prefs = {"download.default_directory": "./"} chrome_options.add_experimental_option("prefs", prefs) await hmm.edit("⬛⬛⬜⬜⬜") driver = webdriver.Chrome(executable_path=Config.CHROME_DRIVER, options=chrome_options) driver.get(url) download_path = "./" driver.command_executor._commands["send_command"] = ( "POST", "/session/$sessionId/chromium/send_command", ) params = { "cmd": "Page.setDownloadBehavior", "params": { "behavior": "allow", "downloadPath": download_path }, } driver.execute("send_command", params) driver.find_element_by_xpath( '//*[@id="__next"]/main/div[3]/div[2]/div[1]/div[1]/div/span[2]' ).click() driver.find_element_by_id("export-menu").click() # driver.find_element_by_xpath("//button[contains(text(),'Export')]").click() sleep(5) # this might take a bit. driver.find_element_by_xpath("//button[contains(text(),'4x')]").click() sleep(5) await hmm.edit("⬛⬛⬛⬜⬜") driver.find_element_by_xpath( "//button[contains(text(),'PNG')]").click() sleep(5) # Waiting for downloading await hmm.edit("⬛⬛⬛⬛⬛") file = "./carbon.png" await hmm.edit("✅RGB Karbon Completed, Uploading Karbon✅") await e.client.send_file( e.chat_id, file, caption= "RGB Karbon by [@PhycoNinja13b](https://github.com/Phyco-Ninja/UniNinja) \n**RGB Colour Code** = `({r},{g},{b})` \n**Theme** = `{theme}`" .format(r=RED, g=GREEN, b=BLUE, theme=The), force_document=True, reply_to=e.message.reply_to_msg_id, ) os.remove("./carbon.png") # Removing carbon.png after uploading await hmm.delete() # Deleting msg
def use_chromium(): use_chromium = Options() use_chromium.binary_location = path return mk_chrome(use_chromium)
def runSelenium(context, browser_name, browser_dict, cpeLocation, cmdSwitches, op_sys, cache_state, hover=False): sparrow_controller = browser_dict.get('controller') cpe_ip = browser_dict.get('ip') is_windows = op_sys == 'windows' sparrow_controller.stopSparrow() # Cleanup leftover .dat files from --bb-on-beer; hopefully this is temporary, waiting on sparrow fix sparrow_controller.removeLeftoverBBs() if not sparrow_controller.startWebdriver(exe_loc=WEBDRIVER_LOC[op_sys], whitelist_ip=context.common.jenkinsIp): return False driver_options = Options() driver_options.binary_location = sparrow_controller.getSparrowFullPath(op_sys) # Account for browser cache state user_data_warm = sparrow_controller.getSparrowUserDataWarmPath(op_sys) if cache_state.lower() == 'warm': driver_options.add_argument('--user-data-dir='+user_data_warm) if not sparrow_controller.removeDir(dir_path=user_data_warm): return False # Initialize new user data dir remote, beerstatus_tab, content_tab = start_remote(cpeLocation, driver_options, sparrow_controller) load_url("http://www.google.com", remote) time.sleep(20) try: remote.quit() except Exception as e: logging.exception("Selenium exception caught quiting remote after iteration on cpe %s" % cpe_ip) with open(context.urlListFile) as f: context.sitelist = f.read().split('\n') for s in cmdSwitches: driver_options.add_argument(s) driver_options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"]) # Values used later in analysis context.urlListLen = len(context.sitelist) context.numClicksTotal = context.listIterations * context.urlListLen context.numClicksPerSite = context.listIterations logging.info("running webdriver test on %s with sparrow switches: %s now.." % (cpe_ip, "; ".join(cmdSwitches))) logging.info("Running selenium webdriver on %s with sitelist: %s" % (cpe_ip, str(context.sitelist))) # k = url, v = beerID ; used to verify that the current beer is unique and new beer_status_dict = {} # initialize for site in context.sitelist: beer_status_dict[site] = None # Pageloads happen here site_count = 1 for i in range(context.listIterations): try: remote, beerstatus_tab, content_tab = start_remote(cpeLocation, driver_options, sparrow_controller) for site in context.sitelist: try: if not site: continue logging.info('Loading url: %s on cpe: %s' % (site, cpe_ip)) remote.switch_to_window(content_tab) if site[0:15] == 'sparrow://crash': res = load_url_and_crash(site, remote) if cache_state.lower() == 'warm': sparrow_controller.removeDir(dir_path=user_data_warm) return res elif hover: load_on_hover(site, remote) else: load_url(site, remote) logging.info('%s loaded successfully, number of sites loaded on %s: %s' % (site, cpe_ip, site_count)) site_count += 1 remote.switch_to_window(beerstatus_tab) # Wait up to 20 seconds for beer ack num_tries = 20 trys = 0 for i in range(num_tries): load_url("sparrow://beerstatus/", remote) if check_beer_status(site, beer_status_dict, remote): break trys += 1 time.sleep(1) if trys == num_tries: logging.info("No beer ack recieved for %s" % site) except Exception as e: logging.exception("Selenium exception caught during site visit on cpe %s" % cpe_ip) remote, beerstatus_tab, content_tab = start_remote(cpeLocation, driver_options, sparrow_controller) continue # Need to quit between iterations in both warm and cold case in order to clean out hint cache try: remote.quit() except Exception as e: logging.exception("Selenium exception caught quiting remote after iteration on cpe %s" % cpe_ip) continue except Exception as e: logging.exception("Selenium exception caught during iteration on cpe %s" % cpe_ip) continue sparrow_controller.stopWebdriver() sparrow_controller.stopSparrow() # Clean up if cache_state.lower() == 'warm': sparrow_controller.removeDir(dir_path=user_data_warm) return True
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.webdriver.common.alert import Alert from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.chrome.options import Options import time from dotenv import load_dotenv import os import pickle import sys opts = Options() opts.binary_location = '/usr/lib/chromium/chromium' opts.add_experimental_option("prefs", { \ "profile.default_content_setting_values.media_stream_mic": 2, # 1:allow, 2:block "profile.default_content_setting_values.media_stream_camera": 2, # 1:allow, 2:block "profile.default_content_setting_values.geolocation": 2, # 1:allow, 2:block "profile.default_content_setting_values.notifications": 2 # 1:allow, 2:block }) driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', chrome_options=opts) load_dotenv() def signin(): # def NCookie(): # if os.path.exists("jar.pkl"):
elapsed = today - last_tw if elapsed.days <= 7: # 直近のツイートが1週間以内の場合は何もせず終了 exit() else: # 直近のツイートから1週間以上経過している場合は # 何らかの理由で前回の処理が実行されていないので再試行 break # HeadlessChromeで擬似的にブラウザでWEBアクセスする(JavaScriptが実行される必要があるため) options = Options() options.add_argument('--headless') ''' driver = webdriver.Chrome(chrome_options=options) ''' options.binary_location = '/app/.apt/usr/bin/google-chrome' driver = webdriver.Chrome(executable_path='chromedriver', chrome_options=options) oa_datetime = None try: # ABNの番組表をスクレイピングして放送日と時間を取得 oa_datetime = scrape_program_table(driver) except Exception as ex: print ex.message plot = None if oa_datetime: try: delay = -8 # 遅れ日数 # twitterアカウントのプロフィール文章から遅れ日数を取得 user_info = api.GetUser(screen_name=__SCREEN_NAME)
im.save(temp_ss_fname) """ #raw_input("Check it!") elem_coords = [] for elem in elems: click_coords = element_coords(elem) print click_coords, elem.tag_name elem_coords.append(click_coords) return elem_coords if __name__ == "__main__": options = Options() # options.binary_location = '/usr/bin/google-chrome-unstable' options.binary_location = '/home/phani/jsgraph/chromium/src/out/Default/chrome' options.add_argument('--headless') options.add_argument('--incognito') options.add_argument('--disable-popup-blocking') # Note: "start-maximized has no effect in headless mode which by default is in 800x600. # We need to explicitly set the window size that we would like. options.add_argument('--start-maximized') # TODO: Automate the setting of the coordinates below for headless mode. options.add_argument('--window-size=1375,738') options.add_argument('--enable-logging=test1.log') options.add_argument('--disk-cache-size=1') # Don't use extra quotes around user-agent here.. this will trip Cloud Fare's Browser Integrity Check # Make sure there are no quotes around the UA by checking here: # https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending options.add_argument( '--user-agent=Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)'
#from pyvirtualdisplay import Display #display = Display(visible=0, size=(800, 800)) #display.start() from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.binary_location="/usr/bin/google-chrome" options.executable_path="/usr/bin/chromedriver" options.add_argument('--headless') options.add_argument('--disable-gpu') options.add_argument('--no-sandbox') options.add_argument('--window-size=1200x600') driver = webdriver.Chrome( "/usr/bin/chromedriver", chrome_options=options, service_args=['--verbose'], service_log_path="{}/chromedriver.log".format("./")) driver.get("http://localhost") print driver.title driver.close() driver.quit()
import logging from selenium import webdriver from selenium.common.exceptions import TimeoutException from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0 from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0 from selenium.webdriver.common.by import By from selenium.webdriver import ChromeOptions from selenium.webdriver.chrome.options import Options import os, time, subprocess # Create a new instance of the Firefox driver #driver = webdriver.Firefox() #C:\Users\EJLNOQC\Desktop\chromedriver chromeDriver = os.path.normpath("C:\Users\EJLNOQC\Desktop\chromedriver.exe") opts = Options() opts.binary_location = "C:\\installed\\chrome\\chrome.exe" os.environ["webdriver.chrome.driver"] = chromeDriver driver = webdriver.Chrome(chromeDriver, chrome_options=opts) driver.maximize_window() # go to the google home page driver.get("http://10.184.73.75:8686/XOAM/login/index.html") driver.find_element_by_id('loginUsername').clear() driver.find_element_by_id('loginUsername').send_keys('admin') driver.find_element_by_id('loginPassword').clear() driver.find_element_by_id('loginPassword').send_keys('Admin!@#123') driver.find_element_by_id('submit').click() WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "ebBtnSearch"))) #ul = driver.find_element_by_xpath("//div[@class='ebBreadcrumbs-list']/ul/li[4]/a")
#!/usr/bin/python3 from selenium import webdriver from selenium.webdriver.chrome.options import Options from pyvirtualdisplay import Display display = Display(visible=0, size=(1280, 1024)) display.start() options = Options() options.binary_location = '/usr/bin/google-chrome' options.add_argument('--window-size=1280,1024') options.add_argument('--no-sandbox') options.add_argument('--disable-dev-shm-usage') prefs = { "download.prompt_for_download": False, "download.default_directory": "/path/to/download/dir", "download.directory_upgrade": True, "profile.default_content_settings.popups": 0, "plugins.plugins_disabled":["Chrome PDF Viewer"], "plugins.always_open_pdf_externally": True, } options.add_experimental_option("prefs",prefs) driver = webdriver.Chrome('/usr/local/bin/chromedriver', chrome_options=options) driver.get('https://www.google.com') driver.save_screenshot("screenshot.png") driver.quit() display.stop()
import pandas as pd import datetime as dt from bs4 import BeautifulSoup as bs import requests import pymongo from splinter import Browser import os from selenium import webdriver from selenium.webdriver.chrome.options import Options ## new deploy#### options = Options() options.binary_location = os.environ.get('GOOGLE_CHROME_BIN') options.add_argument('--headless') options.add_argument('--disable-gpu') options.add_argument('--no-sandbox') browser = webdriver.Chrome(executable_path=str( os.environ.get('CHROMEDRIVER_PATH')), options=options) # executable_path = {'executable_path':'GOOGLE_CHROME_BIN '} def scrape_mars(): url = 'https://mars.nasa.gov/news/' ######## '''for splinter traversal''' ########
# sudo pip3 install selenium # sudo apt install chromium-chromedriver from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.chrome.options import Options from getpass import getpass import sys USERNAME = input("Username (e.g. FI123456): ") NIF = input("NIF (e.g. 00000014Z): ") PASSWORD = getpass("Password (e.g. 1234): ") chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.binary_location = '/usr/bin/chromium-browser' driver = webdriver.Chrome(executable_path='/usr/lib/chromium-browser/chromedriver', chrome_options=chrome_options) driver.get("https://www.fiarebancaetica.coop/") button = driver.find_element_by_class_name("client-button") if button.is_displayed(): button.click() else: print("No button displayed") sys.exit(1) actions = driver.find_element_by_id("actions") button = actions.find_element_by_xpath("li/a") assert(button.text.lower() == "castellano") button.click()
async def carbon_api(e): RED = random.randint(0, 256) GREEN = random.randint(0, 256) BLUE = random.randint(0, 256) THEME = [ "3024-night", "a11y-dark", "blackboard", "base16-dark", "base16-light", "cobalt", "dracula", "duotone-dark", "hopscotch", "lucario", "material", "monokai", "night-owl", "nord", "oceanic-next", "one-light", "one-dark", "panda-syntax", "paraiso-dark", "seti", "shades-of-purple", "solarized", "solarized%20light", "synthwave-84", "twilight", "verminal", "vscode", "yeti", "zenburn", ] CUNTHE = random.randint(0, len(THEME) - 1) The = THEME[CUNTHE] godboy = await edit_or_reply(e, "⬜⬜⬜⬜⬜") CARBON = "https://carbon.now.sh/?bg=rgba({R}%2C{G}%2C{B}%2C1)&t={T}&wt=none&l=auto&ds=false&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=56px&ph=56px&ln=false&fl=1&fm=Fira%20Code&fs=14px&lh=152%25&si=false&es=2x&wm=false&code={code}" CARBONLANG = "en" textx = await e.get_reply_message() pcode = e.text if pcode[7:]: pcode = str(pcode[7:]) elif textx: pcode = str(textx.message) # Importing message to module code = quote_plus(pcode) # Converting to urlencoded url = CARBON.format(code=code, R=RED, G=GREEN, B=BLUE, T=The, lang=CARBONLANG) chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.binary_location = CHROME_BIN # fixed by madboy482 # SAY NO TO KANGS, ELSE GEND FAD DI JAYEGI chrome_options.add_argument("--window-size=1920x1080") chrome_options.add_argument("--disable-dev-shm-usage") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-gpu") prefs = {"download.default_directory": "./"} chrome_options.add_experimental_option("prefs", prefs) await godboy.edit("⬛⬛⬜⬜⬜") driver = webdriver.Chrome(executable_path=Config.CHROME_DRIVER, options=chrome_options) driver.get(url) download_path = "./" driver.command_executor._commands["send_command"] = ( "POST", "/session/$sessionId/chromium/send_command", ) params = { "cmd": "Page.setDownloadBehavior", "params": { "behavior": "allow", "downloadPath": download_path }, } driver.execute("send_command", params) driver.find_element_by_xpath("//button[contains(text(),'Export')]").click() await asyncio.sleep(2) # this might take a bit. # driver.find_element_by_xpath("//button[contains(text(),'4x')]").click() # await asyncio.sleep(5) await godboy.edit("⬛⬛⬛⬜⬜") # driver.find_element_by_xpath("//button[contains(text(),'PNG')]").click() await asyncio.sleep(2) # Waiting for downloading await godboy.edit("⬛⬛⬛⬛⬛") file = "./carbon.png" await godboy.edit("✅RGB Karbon Completed, Uploading Karbon✅") await e.client.send_file( e.chat_id, file, caption=f"Here's your karbonrgb", force_document=True, reply_to=e.message.reply_to_msg_id, ) os.remove("./carbon.png") await godboy.delete() # Deleting msg
async def carbon_api(e): if not e.text[0].isalpha() and e.text[0] not in ("/", "#", "@", "!"): """ A Wrapper for carbon.now.sh """ await e.edit("`Processing..`") CARBON = 'https://carbon.now.sh/?l={lang}&code={code}' global CARBONLANG textx = await e.get_reply_message() pcode = e.text if pcode[8:]: pcodee = str(pcode[8:]) if "|" in pcodee: pcode, skeme = pcodee.split("|") else: pcode = pcodee skeme = None elif textx: pcode = str(textx.message) skeme = None # Importing message to module code = quote_plus(pcode) # Converting to urlencoded await e.edit("`Meking Carbon...\n25%`") url = CARBON.format(code=code, lang=CARBONLANG) chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.binary_location = GOOGLE_CHROME_BIN chrome_options.add_argument("--window-size=1920x1080") chrome_options.add_argument("--disable-dev-shm-usage") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-gpu") prefs = {'download.default_directory': './'} chrome_options.add_experimental_option('prefs', prefs) driver = webdriver.Chrome(executable_path=CHROME_DRIVER, options=chrome_options) driver.get(url) await e.edit("`Be Patient...\n50%`") download_path = './' driver.command_executor._commands["send_command"] = ( "POST", '/session/$sessionId/chromium/send_command') params = { 'cmd': 'Page.setDownloadBehavior', 'params': { 'behavior': 'allow', 'downloadPath': download_path } } command_result = driver.execute("send_command", params) driver.find_element_by_xpath( '/html/body/div[1]/main/div[3]/div[2]/div[1]/div[1]/div/span[2]' ).click() if skeme != None: k_skeme = driver.find_element_by_xpath( '/html/body/div[1]/main/div[3]/div[2]/div[1]/div[1]/div/span[2]/input' ) k_skeme.send_keys(skeme) k_skeme.send_keys(Keys.DOWN) k_skeme.send_keys(Keys.ENTER) else: color_scheme = str(random.randint(1, 29)) driver.find_element_by_id( ("downshift-0-item-" + color_scheme)).click() driver.find_element_by_id("export-menu").click() driver.find_element_by_xpath("//button[contains(text(),'4x')]").click() driver.find_element_by_xpath( "//button[contains(text(),'PNG')]").click() await e.edit("`Processing..\n75%`") # Waiting for downloading sleep(2.5) color_name = driver.find_element_by_xpath( '/html/body/div[1]/main/div[3]/div[2]/div[1]/div[1]/div/span[2]/input' ).get_attribute('value') await e.edit("`Done Dana Done...\n100%`") file = './carbon.png' await e.edit("`Uploading..`") await e.client.send_file( e.chat_id, file, caption= "<< `Here's your carbon!` \n **Carbonised by** [TeleBotHelp.](https://telegra.ph/TeleBot-07-08)>>\n**Colour Scheme: **`{}`" .format(color_name), force_document=True, reply_to=e.message.reply_to_msg_id, ) os.remove('./TeleBot.png') driver.quit() # Removing carbon.png after uploading await e.delete() # Deleting msg
import requests import os, sys from tda import auth, client from tda.orders.equities import equity_buy_market, equity_buy_limit from tda.orders.common import Duration, Session import tda from selenium.webdriver.chrome.options import Options options = Options() options.binary_location = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"# Location where chrome.exe is located on your system Then when you authenticate. excecutable_path is where chromedriver is located on your system. ### AUTENTICATE ### try: c = auth.client_from_token_file(config.token_path, config.api_key) except FileNotFoundError: from selenium import webdriver with webdriver.Chrome(chrome_options=options, executable_path= r'C:\Users\absco\Anaconda3\envs\td_ameritrade\chromedriver') as driver: c = auth.client_from_login_flow( driver, config.api_key, config.redirect_uri, config.token_path) currentdir = os.path.dirname(os.path.realpath(__file__)) # currentdir = os.path.abspath('') parentdir = os.path.dirname(currentdir)
async def carbon_api(e): if not e.text[0].isalpha() and e.text[0] not in ("/", "#", "@", "!"): """ A Wrapper for carbon.now.sh """ await e.edit("`Processing..`") CARBON = 'https://carbon.now.sh/?l={lang}&code={code}' global CARBONLANG textx = await e.get_reply_message() pcode = e.text if pcode[8:]: pcode = str(pcode[8:]) elif textx: pcode = str(textx.message) # Importing message to module code = quote_plus(pcode) # Converting to urlencoded await e.edit("`Meking Carbon...\n25%`") url = CARBON.format(code=code, lang=CARBONLANG) chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.binary_location = GOOGLE_CHROME_BIN chrome_options.add_argument("--window-size=1920x1080") chrome_options.add_argument("--disable-dev-shm-usage") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-gpu") prefs = {'download.default_directory': './'} chrome_options.add_experimental_option('prefs', prefs) driver = webdriver.Chrome(executable_path=CHROME_DRIVER, options=chrome_options) driver.get(url) await e.edit("`Be Patient...\n50%`") download_path = './' driver.command_executor._commands["send_command"] = ( "POST", '/session/$sessionId/chromium/send_command') params = { 'cmd': 'Page.setDownloadBehavior', 'params': { 'behavior': 'allow', 'downloadPath': download_path } } command_result = driver.execute("send_command", params) driver.find_element_by_xpath( "//button[contains(text(),'Export')]").click() #driver.find_element_by_xpath("//button[contains(text(),'4x')]").click() #driver.find_element_by_xpath("//button[contains(text(),'PNG')]").click() await e.edit("`Processing..\n75%`") # Waiting for downloading sleep(2.5) await e.edit("`Done Dana Done...\n100%`") file = './carbon.png' await e.edit("`Uploading..`") await e.client.send_file( e.chat_id, file, caption= "<< Here's your carbon, \n Carbonised by [PYDROID](https://www.github.com/IamArjun078/PYDROIDUSERBOT)>> ", force_document=True, reply_to=e.message.reply_to_msg_id, ) os.remove('./PYDROID.png') driver.quit() # Removing carbon.png after uploading await e.delete() # Deleting msg
import os, sys from tda import auth, client from tda.orders.equities import equity_buy_market, equity_buy_limit from tda.orders.common import Duration, Session import tda currentdir = os.path.dirname(os.path.realpath(__file__)) # currentdir = os.path.abspath('') parentdir = os.path.dirname(currentdir) sys.path.append(parentdir) import config from selenium.webdriver.chrome.options import Options options = Options() options.binary_location = "/home/hopper/chromedriver" # Then when you authenticate. excecutable_path is where chromedriver is located on your system. ### AUTENTICATE ### try: c = auth.client_from_token_file(config.token_path, config.api_key) except FileNotFoundError: from selenium import webdriver with webdriver.Chrome( chrome_options=options, executable_path= r'C:\Users\absco\Anaconda3\envs\td_ameritrade\chromedriver' ) as driver: c = auth.client_from_login_flow(driver, config.api_key, config.redirect_uri, config.token_path)
return b'\x00' ret = bytearray() ret.append(0x0b) ret += uleb128_encode(len(string)) ret += string.encode('utf-8') return ret options = Options() options.headless = True options.add_argument('--window-size=1920,1080') options.add_experimental_option( 'prefs', {'download.default_directory': str(os.getcwd())}) if chrome_path: options.binary_location = chrome_path if chrome_driver_path: driver = webdriver.Chrome(chrome_driver_path, options=options) else: driver = webdriver.Chrome(options=options) driver.get('https://osu.ppy.sh') wait = WebDriverWait(driver, 10) wait.until(EC.title_contains('welcome')) sign_in = driver.find_element_by_xpath( '''//div[@class='osu-layout__section osu-layout__section--full js-content home_index']''' '''/nav[@class='osu-layout__row']/div[@class='landing-nav hidden-xs']/div[@class='landing-nav__section'][2]''' '''/a[@class='landing-nav__link js-nav-toggle js-click-menu js-user-login--menu']'''
# TODO: Implement headless for selenium import requests, time, os from bs4 import BeautifulSoup from selenium import webdriver from lxml import html from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys chrome_options = Options() #chrome_options.add_argument("--headless") chrome_options.binary_location = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" url = ("https://twitter.com/realDonaldTrump/status/1265827032707072000") driver = webdriver.Chrome(executable_path=os.path.abspath( 'C:/Users/alexf/OneDrive/Documents/Python Projects/chromedriver.exe'), options=chrome_options) def scroll_to_bottom(driver): # Empty list for all the usernames scraped FULL_LIST = [] old_position = 0 new_position = None while new_position != old_position: # Get old scroll position old_position = driver.execute_script( ("return (window.pageYOffset !== undefined) ?" " window.pageYOffset : (document.documentElement ||"
import os import time from selenium import webdriver from selenium.webdriver.chrome.options import Options from pageobjects.login import LoginPage from pageobjects.menu import MainMenu chromedriver_path = "./chromedriver" electron_path = "/Users/teo/dev/sc-ui/dist/AppGate XDP-darwin-x64/AppGate XDP.app/Contents/MacOS/Electron" opts = Options() opts.binary_location = electron_path driver = webdriver.Chrome(executable_path=chromedriver_path, chrome_options=opts) driver.implicitly_wait(15) # seconds time.sleep(3) # wait for application to start login_page = LoginPage(driver) login_page.login('teoman.soygul', os.environ['PASS']) time.sleep(15) # wait for sign in main_menu = MainMenu(driver) main_menu.logout() time.sleep(3) # wait for logout main_menu.quit() driver.quit()
gp = graph.begin() coordinates = [] # create the list for coordinates coordinates = generate_coordinates(width, height, coordinates) # generates coordinates based on the diff and the resolution coordinates = generate_random_coordinates(coordinates) # already generated coordinates are shuffled randomly chrome_options = Options() chrome_options.add_extension(".\process_monitor.crx") # Adding the extension to chrome # chrome_options.add_extension("C:\\Users\crawler\Desktop\Crawler\process_monitor.crx") chromium_path = ".\chrome-win32\chrome.exe" # Use the portable chromium browser # If chromium browser is not required then by removing the above chromium path, it will start using the default one # The default will be developer google chrome. # ONly Dev channel google chrome can support the extension used here. This extension used a particular API. # The API used is "chrome.processes" and it is available only in the chrome dev-channel and chromium browser chrome_options.binary_location = chromium_path browser=webdriver.Chrome(".\chromedriver.exe", chrome_options=chrome_options ) # chrome options is to add the extension to the chrome as soon as it starts. check_crawler_name = get_crawler_name(remote_crawler) if check_crawler_name != "CRAWLER-1" and check_crawler_name != "local-computer": statement = 'MATCH (n:New_Tab) WHERE ((n.Crawled_by="CRAWLER-1") AND (n.Will_be_crawled_by="'+check_crawler_name+'") AND (n.target_crawled="no")) RETURN n.URL,n.PID' urls=[] pids=[] cursor = gp.run(statement).data() for each in cursor: x = list(each.values()) if len(x[0]) > 7: urls.append(x[0]) pids.append(x[1]) else:
def create_chromedriver(self): """ Since we have many functions we can perform we consolidate chromedriver code here. """ # set up options object chrome_options = Options() # if we have chrome binary set it up if self.chrome_binary_path: chrome_options.binary_location = self.chrome_binary_path # live dangerously if self.allow_insecure: chrome_options.add_argument('--allow-running-insecure-content') # thank god for this option chrome_options.add_argument('--mute-audio') # if we are headless we also mix up window size a bit if self.headless: chrome_options.add_argument('headless') chrome_options.add_argument('disable-gpu') window_x = random.randrange(1050,1920) window_y = random.randrange(900,1080) chrome_options.add_argument('window-size=%sx%s' % (window_x,window_y)) # if we have a ua set it here if self.ua: chrome_options.add_argument('user-agent='+self.ua) # 'desired_capabilities' is essentially a second way to set options for chrome # we set loggingPrefs to turn on the performance log which we need to analyze network traffic # see: https://sites.google.com/a/chromium.org/chromedriver/logging/performance-log # pageLoadStrategy is set to 'none' to make sure we don't get stuck on pages that never finish loading # once 'eager' is implemented in chromedriver that may be preferable # see: https://w3c.github.io/webdriver/#dfn-table-of-page-load-strategies chrome_capabilities = { 'loggingPrefs': {'performance': 'ALL'}, 'pageLoadStrategy': 'none' } # attempt to start driver, fail gracefull otherwise try: # if we have chromedriver path set it up if self.chromedriver_path: driver = webdriver.Chrome( self.chromedriver_path, desired_capabilities=chrome_capabilities, chrome_options=chrome_options ) else: driver = webdriver.Chrome( desired_capabilities=chrome_capabilities, chrome_options=chrome_options ) except: return None # allow one minute before we kill it, seperate from browser_wait driver.set_page_load_timeout(self.page_timeout_seconds) return driver
from selenium.webdriver.chrome.options import Options from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.common.keys import Keys from bs4 import BeautifulSoup from captcha_solver import CaptchaSolver domain = 'https://cart.books.com.tw' login_url = 'https://cart.books.com.tw/member/login' username = '******' password = '******' solver = CaptchaSolver('2captcha', api_key='密碼') options = Options() options.binary_location = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" webdriver_path = 'C:\\chromedriver_win32\\chromedriver.exe' driver = webdriver.Chrome(executable_path=webdriver_path, options=options) #登入 def login(): login_id = driver.find_element_by_name('login_id') login_pswd = driver.find_element_by_name('login_pswd') captcha = driver.find_element_by_name('captcha') captcha_img = driver.find_element_by_id('captcha_img') login_button = driver.find_element_by_id('books_login') captcha_img.screenshot('captcha_image.png')
def setUp(self): chromium_path = '/usr/bin/chromium' chromedriver_path = './chromedriver' opts = Options() opts.binary_location = chromium_path opts.add_experimental_option("prefs", { "download.default_directory": "./test_downloaded", "helperApps.neverAsk.saveToDisk": "octet/stream", "directory_upgrade": True, "profile": {"default_content_settings": {"multiple-automatic-downloads": 1}} }) self.driver = webdriver.Chrome(chrome_options=opts, executable_path=chromedriver_path) #self.driver = webdriver.Firefox() url = os.getenv('TEST_URL', config.url) self.driver.get(url) self.__load_pages() # Sets up by redirecting to login page main_page = page.MainPage(self.driver) main_page.click_login_link()