def before_all(context): call( [ "killall", "-9", "chrome" ] ) options = Options() options.add_extension(path_to_chrome_extension) #options.add_argument("--remote-debugging-port=9222") options.add_argument("--start-maximized") context.driver = webdriver.Chrome(executable_path=path_to_chrome_driver, chrome_options=options)
def __get_crome_options(self): ''' Creates chrome_options with extension to be added ''' chrome_options = Options() home_dir = expanduser("~") chrome_version = self._config_reader.get('versions.chrome_version', None) if chrome_version: binary_path = os.path.join(home_dir, chrome_version) chrome_options.add_argument("binary=" + binary_path) chrome_extension = self._config_reader.get('extensions.chrome_extension', None) if chrome_extension: extension_path = os.path.join(home_dir, chrome_extension) chrome_options.add_extension(extension_path) profile_prefs = self._config_reader.get('profile_prefs.chrome', None) for pref in profile_prefs: pref_val = profile_prefs[pref] if pref_val: chrome_options.add_argument(pref + "=" + pref_val) else: chrome_options.add_argument(pref) return chrome_options
def fetch_menu_image(dir, path, proxy=None): options = None if proxy is not None: extpath = os.path.join(dir, CHROME_EXTENSION_FILENAME) proxy.generate_extension(extpath) options = Options() options.add_extension(extpath) for image in fetch_menu(dir, path, options): yield image
def setUpModule(): global driver print "starting setUpModule" call( [ "killall", "-9", "chrome" ] ) options = Options() options.add_extension(path_to_chrome_extension) options.add_argument("--start-maximized") driver = webdriver.Chrome(executable_path=path_to_chrome_driver, chrome_options=options) print "finished setUpModule"
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 create_chrome_driver(host=None, port=None): co = Options() if host is not None and port is not None: manifest_json = read_script('./proxy_ext/manifest.json') background_js = read_script('./proxy_ext/background.js', host=host, port=port, user=username, password=password) with zipfile.ZipFile(plugin_file, 'w') as zp: zp.writestr("manifest.json", manifest_json) zp.writestr("background.js", background_js) co.add_extension(plugin_file) driver = webdriver.Remote( command_executor=diver_executable_path, desired_capabilities=co.to_capabilities() ) 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 __init__(self, delay=1, browser="firefox"): """delay: Number of extra seconds to wait when a page is supposedly loaded. Try raising this in case of weird errors. browser: `firefox` or `chrome`. The ChromeDriver executable for your OS must be inside the bin directory for Chrome to work. Get it from: http://chromedriver.storage.googleapis.com/index.html """ self.extra_delay = delay # extra time to wait after each operation (s) self.temp_dir = mkdtemp() self.vdisplay = Xvfb() self.vdisplay.start() if browser == "firefox": profile = FirefoxProfile() # Open links in same window profile.set_preference("browser.link.open_newwindow", 1) # Download to temp dir, for files we can't open inline profile.set_preference("browser.download.dir", self.temp_dir) profile.set_preference("browser.download.folderList", 2) profile.set_preference("browser.download.manager.showWhenStarting", "False") profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/msword, application/vnd.ms-word, application/rtf, application/octet-stream") # Add extension for overriding Content-Disposition headers, etc extensions_dir = os_sep.join(['bin', 'firefox-plugins-enabled']) for filename in listdir(extensions_dir): fullfilename = os_sep.join([extensions_dir, filename]) profile.add_extension(extension=fullfilename) driver = Firefox(profile) elif browser == "chrome": # Add extension for overriding Content-Disposition headers options = ChromeOptions() options.add_extension('bin/undisposition.crx') driver = Chrome(executable_path='bin/chromedriver', chrome_options=options) else: raise Exception("Not a valid browser name") self.selenium_driver = EventFiringWebDriver(driver, CustomListener()) """selenium_driver is a EventFiringWebDriver, so that it can trigger javascript event """ self.browser_version = " ".join([ self.selenium_driver.capabilities['browserName'], self.selenium_driver.capabilities['version']]) # 'Firefox 33.0'
def _web_driver_with_proxy(): # fix proxy problem # profile = webdriver.FirefoxProfile() # profile.set_preference("network.proxy.type", 1); # profile.set_preference('network.proxy.http', "114.66.81.130") # profile.set_preference("network.proxy.http_port", 8080); # driver = webdriver.Firefox(firefox_profile=profile) pluginfile = 'proxy_auth_plugin.zip' if False == os.path.exists(pluginfile): generate_chrome_proxy() co = Options() co.add_argument("--start-minimized") co.add_extension(pluginfile) driver = webdriver.Chrome(chrome_options=co) return 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 __init__(self, user_agent=None, wait_time=2, fullscreen=False, extensions=None, **kwargs): options = Options() if user_agent is not None: options.add_argument("--user-agent=" + user_agent) if fullscreen: options.add_argument('--kiosk') if extensions: for extension in extensions: options.add_extension(extension) self.driver = Chrome(chrome_options=options, **kwargs) self.element_class = WebDriverElement self._cookie_manager = CookieManager(self.driver) super(WebDriver, self).__init__(wait_time)
class HypothesisSeleniumDriver(): def __init__(self,browser,ext_path=None): self.ext_path = ext_path self.driver = None self.options = Options() if browser == 'firefox': self.driver = webdriver.Firefox() if browser == 'chrome': if self.ext_path is not None: self.options.add_extension(self.ext_path) self.options.add_experimental_option('excludeSwitches', ['test-type','ignore-certificate-errors']) # https://code.google.com/p/chromedriver/issues/detail?id=1081 self.driver = webdriver.Chrome(chrome_options=self.options) if browser == 'ie': self.driver = webdriver.Ie() self.drivername = self.driver.name #self.driver.implicitly_wait(HypothesisSeleniumTiming().very_long_wait) self.driver.set_page_load_timeout(HypothesisSeleniumTiming().wait_for_page_load_secs) self.driver.set_script_timeout(HypothesisSeleniumTiming().wait_for_script_secs)
from os import getcwd from bs4 import BeautifulSoup from requests import get from shutil import copyfileobj from time import sleep from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() #chrome_options.add_argument("--headless") chrome_options.add_argument("--window-size=1024x768") chrome_options.add_extension('/home/lunu/Apps/ublock/ublock.crx') chrome_driver = '/home/lunu/Apps/chromedriver/chromedriver' browser = webdriver.Chrome(chrome_options=chrome_options, executable_path=chrome_driver) #setup browser.get('https://www1.cartooncrazy.tv/anime/bleach/') sleep(10) show_name = 'Bleach' start_from = 0 # from which no. link should download start from episode_no = 1 # Starting no. of episode. to_download = 10 # No. of episodes to be downloaded episodesStale = browser.find_elements_by_css_selector( '#episode-list-entry-tbl a') episodesStale.reverse() episodes = [] episodesStale = episodesStale[start_from:] for episode in episodesStale:
from selenium import webdriver from selenium.webdriver.chrome.options import Options import time def main(driver): fp = open('input.txt') urlList = list() for each in fp: each = each.strip() urlList.append(each) fp.close() for url in urlList: driver.get(url) time.sleep(1) if __name__ == '__main__': chrome_options = Options() chrome_options.add_extension('TrackingObserver.crx') driver = webdriver.Chrome(executable_path="C:\chrome\chromedriver.exe", chrome_options=chrome_options) try: main(driver) except KeyboardInterrupt: driver.close()
def main(): parser = argparse.ArgumentParser( description='This command will record a VClass page') parser.add_argument('-u', '--url', type=str, default='', help='URL of vclass') parser.add_argument('-d', '--duration', type=float, default=0, help='Duration of class in minutes') parser.add_argument('-n', '--name', type=str, default='', help='Name of downloads folder') parser.add_argument('-a', '--username', type=str, default='ضبط کننده', help='Username of skyroom user') parser.add_argument('-e', '--encoding', type=str, default='no-encode', help='Encoding quality, see readme.md') parser.add_argument('-v', '--video', type=str, default='', help='Video to encode') args = parser.parse_args() SOURCE_DIR = os.path.abspath(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(SOURCE_DIR) if args.url != '' and args.video != '': print('You cant define the -v argument for recording') exit() if args.url != '': try: os.mkdir(os.path.join(BASE_DIR, 'downloads', args.name)) except FileExistsError: pass download_path = os.path.join( BASE_DIR, 'downloads', args.name, datetime.now().strftime("%Y-%m-%d--%H-%M")) os.mkdir(download_path) chrome_options = Options() chrome_options.add_extension(os.path.join(SOURCE_DIR, 'skyroom.crx')) chrome_options.add_experimental_option( "prefs", { "download.default_directory": download_path, "download.prompt_for_download": False, "download.directory_upgrade": True, "safebrowsing.enabled": True }) chrome_options.add_argument("--no-sandbox") chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.add_argument("disable-infobars") logger.info('Opening google chrome') driver = None for retry_number in range(10): try: if driver: logger.info('Driver is not none, close it.') driver.close() except Exception as e: logger.exception(e) try: driver = webdriver.Chrome(options=chrome_options) driver.implicitly_wait(10) time.sleep(2) driver.maximize_window() time.sleep(1) driver.maximize_window() break except Exception as e: logger.exception(e) logger.info('Create new window for not closing browser') for retry_number in range(10): try: if len(driver.window_handles) < 2: driver.execute_script( "window.open('about:blank', 'tab2');") time.sleep(2 * (retry_number + 1)) break except Exception as e: logger.exception(e) logger.info('Configure skyroom extension') for retry_number in range(10): try: if len(driver.window_handles) > 1: driver.switch_to.window(driver.window_handles[0]) driver.get("chrome-extension://" "pejdnafppnpfimpnipdkiidjancinenc/options.html") ui.Select(driver.find_element_by_id( 'video_bitrate')).select_by_value('1000') ui.Select(driver.find_element_by_id( 'audio_bitrate')).select_by_value('32') driver.find_element_by_id('btnSave').click() time.sleep(2 * (retry_number + 1)) break except Exception as e: logger.exception(e) logger.info('Open vclass') for retry_number in range(10): try: driver.switch_to.window(driver.window_handles[0]) driver.get(args.url) time.sleep(2 * (retry_number + 1)) break except Exception as e: logger.exception(e) logger.info('Login as guest') for retry_number in range(10): try: force_refresh(driver) time.sleep(5 * retry_number) goto_class(driver) driver.find_element_by_xpath("//input[@class='full-width']") driver.execute_script( "document.querySelector('.dlg-nickname .full-width').value" f" = '{args.username}';") driver.execute_script( "document.querySelector('.dlg-nickname .btn').click();") break except Exception as e: logger.exception(e) logger.info('Start record') for retry_number in range(10): try: open_skyroom_popup() if not is_tab_in_recording(): if not pyautogui.pixelMatchesColor(*START_RECORDING_ICON, (255, 0, 0)): close_skyroom_popup() raise Exception('Recording red color not found :|') pyautogui.click(*START_RECORDING_ICON) time.sleep(5) if not pyautogui.pixelMatchesColor( *BETWEEN_PAUSE_AND_STOP_ICON, (245, 245, 245)): raise Exception('I can not see pause and stop icon!') if not is_tab_in_recording(): raise Exception('Tab blue recording icon can not be seen!') close_skyroom_popup() break except Exception as e: logger.exception(e) close_chrome_notification() logger.info('Recording is started, watch for freeze detection!') end_time = datetime.now() + timedelta(minutes=args.duration) old_screenshot = cv2.imdecode( np.frombuffer(driver.get_screenshot_as_png(), np.uint8), -1) next_failure_test = datetime.now() + FAILURE_TEST_INTERVAL while datetime.now() < end_time and is_need_recording(): if datetime.now() >= next_failure_test: for retry_number in range(10): try: cur_screenshot = cv2.imdecode( np.frombuffer(driver.get_screenshot_as_png(), np.uint8), -1) similarity = ssim(old_screenshot, cur_screenshot, multichannel=True) if similarity > 0.98: logger.info( 'Screenshots are too similar, refresh!') force_refresh(driver) goto_class(driver) old_screenshot = cur_screenshot break except Exception as e: logger.exception(e) next_failure_test = datetime.now() + FAILURE_TEST_INTERVAL time.sleep( max(0, min(10, (end_time - datetime.now()).total_seconds()))) logger.info('Time is over, stop recording') for retry_number in range(10): try: time.sleep(5 * retry_number) if is_tab_in_recording(): open_skyroom_popup() if not pyautogui.pixelMatchesColor(*STOP_RECORDING_ICON, (0, 0, 0)): raise Exception( 'I can not see stop recording black icon') pyautogui.click(*STOP_RECORDING_ICON) time.sleep(5) close_skyroom_popup() if is_tab_in_recording(): raise Exception( 'I stop recording but tab is in recording :|') if len(driver.window_handles) < 2: raise Exception('Recording window is not open :(') break except Exception as e: logger.exception(e) # download file for retry_number in range(10): try: time.sleep(5) driver.switch_to.window(driver.window_handles[1]) time.sleep(0.5) driver.find_element_by_id('download').click() time.sleep(5 * (1 + retry_number)) if not pyautogui.pixelMatchesColor(*CENTER_OF_DOWNLOAD_BAR, (255, 255, 255)): raise Exception('I can not see download bar') break except Exception as e: logger.exception(e) # close windows time.sleep(60 + 3 * args.duration) for retry_number in range(100): try: if len(os.listdir(download_path)) == 0 or not os.listdir( download_path)[0].endswith('.webm'): raise Exception('Downloaded file can not be found!') time.sleep(10 * (1 + retry_number)) break except Exception as e: logger.exception(e) for retry_number in range(100): try: driver.switch_to.window(driver.window_handles[0]) driver.close() time.sleep(3) driver.switch_to.window(driver.window_handles[0]) driver.close() break except Exception as e: logger.exception(e) webm_file = os.path.join(download_path, os.listdir(download_path)[0]) new_webm_file = os.path.join(download_path, 'video.webm') os.rename(webm_file, new_webm_file) output_mp4 = os.path.join(download_path, 'video.mp4') else: new_webm_file = args.video output_mp4 = os.path.join(os.path.dirname(args.video), 'video.mp4') ffmpeg_pipe = ffmpeg.input(new_webm_file) if args.encoding == "high": ffmpeg_pipe.output(output_mp4, **{ 'vcodec': 'libx264', 'acodec': 'aac', 'b:a': '128k', }, crf='36', tune='stillimage', preset='veryfast', r='25', movflags='+faststart').run() elif args.encoding == "medium": ffmpeg_pipe.output(output_mp4, **{ 'vcodec': 'libx264', 'acodec': 'aac', 'b:a': '60k', }, crf='36', tune='stillimage', preset='veryfast', s='852x480', r='20', movflags='+faststart').run() elif args.encoding == "low": ffmpeg_pipe.output(output_mp4, **{ 'vcodec': 'libx264', 'acodec': 'aac', 'b:a': '60k', }, crf='36', tune='stillimage', preset='veryfast', s='640x360', r='15', movflags='+faststart').run()
from selenium import webdriver from selenium.webdriver.common.keys import Keys import time import ElementExistance as ele import csv import sys import os from selenium.webdriver.chrome.options import Options executable_path = "/home/gopal_admin/Music/chromedriver" os.environ["webdriver.chrome.driver"] = executable_path chrome_options = Options() # chrome_options.add_argument('--proxy-server=45.77.218.171:8080') # chrome_options.add_extension('/home/gopal_admin/Downloads/Browsec-VPN-Free-and-Unlimited-VPN_v3.19.6.crx') chrome_options.add_extension( '/home/gopal_admin/Downloads/Betternet-Unlimited-Free-VPN-Proxy_v5.2.1.crx' ) # chrome_options.add_extension('/home/gopal_admin/Downloads/TunnelBear-VPN_v2.0.2.crx') # chrome_options.add_extension('/home/gopal_admin/Downloads/Hotspot-Shield-VPN-Free-Proxy-–-Unblock-Sites_v3.3.21.crx') driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options) time.sleep(15) driver.get("https://www.google.com") # driver.quit() keyword = "africa autoclaved aerated concrete market" #96 dmi dmi = 'www.datamintelligence.com' rank = 0
from selenium import webdriver #from selenium.webdriver.common.desired_capabilities import DesiredCapabilities #cap = DesiredCapabilities().Firefox #cap["marionette"] = False from selenium.webdriver.chrome.options import Options executable_path = "/Users/ASUS-X405U/chromedriver.exe" chrome_options = Options() chrome_options.add_extension('/Users/ASUS-X405U/Documents/Metamask.crx') driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options) driver.get("http://192.168.0.24:3000/automoviles.html") button = driver.find_element_by_xpath( '/html[1]/body[1]/section[1]/div[2]/div[3]/button[1]') button.click()
def start_driver(self): """Start a new Selenium web driver and install the bundled extension.""" if self.browser in (CHROME, EDGE): # make extension ID constant across runs # create temp directory # TODO does tmp_dir actually get cleaned up? self.tmp_dir = tempfile.TemporaryDirectory() # pylint:disable=consider-using-with new_extension_path = os.path.join(self.tmp_dir.name, "src") # copy extension sources there copytree(os.path.join(self.pb_dir, 'src'), new_extension_path) # update manifest.json manifest_path = os.path.join(new_extension_path, "manifest.json") with open(manifest_path, "r", encoding="utf-8") as f: manifest = json.load(f) # this key and the extension ID # must both be derived from the same private key manifest[ 'key'] = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArMdgFkGsm7nOBr/9qkx8XEcmYSu1VkIXXK94oXLz1VKGB0o2MN+mXL/Dsllgkh61LZgK/gVuFFk89e/d6Vlsp9IpKLANuHgyS98FKx1+3sUoMujue+hyxulEGxXXJKXhk0kGxWdE0IDOamFYpF7Yk0K8Myd/JW1U2XOoOqJRZ7HR6is1W6iO/4IIL2/j3MUioVqu5ClT78+fE/Fn9b/DfzdX7RxMNza9UTiY+JCtkRTmm4ci4wtU1lxHuVmWiaS45xLbHphQr3fpemDlyTmaVoE59qG5SZZzvl6rwDah06dH01YGSzUF1ezM2IvY9ee1nMSHEadQRQ2sNduNZWC9gwIDAQAB" # noqa:E501 pylint:disable=line-too-long # remove the 5MB limit on Chrome extension local storage if 'unlimitedStorage' not in manifest['permissions']: manifest['permissions'].append('unlimitedStorage') with open(manifest_path, "w", encoding="utf-8") as f: json.dump(manifest, f) opts = ChromeOptions() if self.browser == CHROME else EdgeOptions() if self.browser_binary: opts.binary_location = self.browser_binary opts.add_argument("--load-extension=" + new_extension_path) # loads parallel extension to run alongside pb if self.load_extension: opts.add_extension(self.load_extension) opts.add_argument("--disable-blink-features=AutomationControlled") opts.add_argument("--disable-crash-reporter") opts.set_capability("acceptInsecureCerts", False) opts.set_capability("unhandledPromptBehavior", "ignore") for _ in range(5): try: if self.browser == CHROME: self.driver = webdriver.Chrome(self.chromedriver_path, options=opts) else: self.driver = webdriver.Edge(options=opts) except ConnectionResetError as e: self.logger.warning( ("%s WebDriver initialization failed:\n" "%s\n" "Retrying ..."), self.browser.capitalize(), str(e)) time.sleep(2) else: break elif self.browser == FIREFOX: opts = self.get_firefox_options() service = FirefoxService(log_path=os.path.devnull) self.driver = webdriver.Firefox(options=opts, service=service) # load Privacy Badger # Firefox requires absolute paths unpacked_addon_path = os.path.abspath( os.path.join(self.pb_dir, 'src')) self.driver.install_addon(unpacked_addon_path, temporary=True) # loads parallel extension to run alongside pb if self.load_extension: parallel_extension_url = os.path.abspath(self.load_extension) self.driver.install_addon(parallel_extension_url) # apply timeout settings self.driver.set_page_load_timeout(self.timeout) self.driver.set_script_timeout(self.timeout) self.driver.maximize_window() # wait for Badger to finish initializing self.load_extension_page() wait_for_script(self.driver, ("let done = arguments[arguments.length - 1];" "chrome.runtime.sendMessage({" " type: 'isBadgerInitialized'" "}, r => done(r));"), execute_async=True) # also disable the welcome page self.driver.execute_async_script( "let done = arguments[arguments.length - 1];" "chrome.runtime.sendMessage({" " type: 'updateSettings'," " data: { showIntroPage: false }" "}, done);")
def browser(ip): """ 浏览器驱动生成 :return: """ print('browser %s' % ip) # ip = '123.163.118.203:9999' chrome_options = Options() # ip代理 chrome_options.add_argument('--proxy-server=' + ip) # chrome_options.add_extension('D:/QTproject/Python_script/golden_words/chajian/vimm_chrome_proxyauth_plugin.zip') chrome_options.add_extension('D:/chajian/vimm_chrome_proxyauth_plugin.zip') chrome_options.add_argument('--ignore-certificate-errors') # chrome_options.add_argument("--user-data-dir=C:/Users/Dell/AppData/Local/Google/Chrome/User Data") #使用当前chrome插件 chrome_options.add_argument('--disable-gpu') chrome_options.add_argument('--disable-plugins') # chrome_options.add_argument('--disable-infobars') # 禁用浏览器正在被自动化程序控制的提示 已经不支持了 chrome_options.add_experimental_option( "excludeSwitches", ['enable-automation', 'enable-logging']) # 禁用浏览器正在被自动化程序控制的提示 chrome_options.add_experimental_option('w3c', False) chrome_options.add_argument('--enable-audio-focus=true') # chrome_options.add_argument('--no-sandbox') # 浏览器插件奔溃 # chrome_options.add_argument('--window-size=2062,1126') # 设置浏览器分辨率(窗口大小) # chrome_options.add_argument('--start-maximized') # 最大化运行(全屏窗口),不设置,取元素会报错 # chrome_options.add_argument('--blink-sett=imagesEnabled=false') # 不加载图片, 提升速度已经不支持了 # 不加载图片, 提升速度 prefs = { "profile.managed_default_content_settings.images": 2, } # 不加载图片, 提升速度 js css 弹框 # prefs = { # 'profile.default_content_setting_values': { # 'images': 2, # 'javascript': 2, # 'notifications': 2, # }, # 'permissions.default.stylesheet': 2 # } # chrome_options.add_experimental_option('prefs', prefs) # chrome_options.add_argument('headless') #无头浏览 # chrome_options.add_argument('--hide-scrollbars') # 隐藏滚动条, 应对一些特殊页面 # chrome_options.add_argument('--disable-javascript') # 禁用javascript # chrome_options.add_argument('–disable-software-rasterizer') # chrome_options.add_argument('--disable-extensions') # chrome_options.add_argument('--user-agent=Mozilla/5.0 (Windows NT 9.0; Win64; x64) AppleWebKit/537.36 ' # '(KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36') #设置user-agent # 允许flash自动运行 # prefs = { # "profile.managed_default_content_settings.images": 1, # "profile.content_settings.plugin_whitelist.adobe-flash-player": 1, # "profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player": 1, # } # chrome_options.add_experimental_option('prefs', prefs) # chrome_driver_path = os.getcwd() + '\chromedriver.exe' # d = DesiredCapabilities.CHROME # d['loggingPrefs'] = { 'performance':'ALL' } # chrome_options.add_argument('--proxy-server={0}'.format(proxy.proxy)) driver = webdriver.Chrome(chrome_options=chrome_options) # chrome_driver_path = 'C:/Users/Dell/AppData/Local/Google/Chrome/Application/chrome.exe' # driver = webdriver.Chrome(executable_path=chrome_driver_path,) driver.set_page_load_timeout(5) return driver
def getNewInstance(self, uid, user, proxy=None, headless=False) -> WebDriver: pluginfile = None try: if proxy is None: if 'proxy' in user: proxy = user['proxy'] options = Options() options.add_argument('--no-sandbox') options.add_argument("--disable-dev-shm-usage") #options.add_argument("--log-level=3") #options.add_argument("--single-process") options.add_argument('media.eme.enabled') options.add_argument("--disable-gpu") options.add_argument('--disable-popup-blocking') #options.add_argument("--window-position=-32000,-32000"); options.add_argument("--disable-blink-features") options.add_argument("--disable-blink-features=AutomationControlled") #options.add_argument("--log-path=" + (os.path.dirname(__file__) or '.') + "/../chrome.log") options.add_argument('--ignore-certificate-errors-spki-list') options.add_argument('--ignore-certificate-errors') options.add_argument('--ignore-ssl-errors') options.add_experimental_option("excludeSwitches", ["enable-automation"]) options.add_experimental_option('useAutomationExtension', False) userDataDir = mkdtemp() self.tempfolder.append(userDataDir) options.add_argument('--user-data-dir=%s' % userDataDir) if 'windowSize' in user: options.add_argument("--window-size=%s" % user['windowSize']) if headless: #options.add_argument("--disable-gpu") options.add_argument("--headless") # Set user agent if available if 'userAgent' in user: options.add_argument('user-agent=%s' % user['userAgent']) #incognito argument disable the use of the proxy, DO NOT SET ! #options.add_argument("--incognito") desired_capabilities = DesiredCapabilities.CHROME.copy() # add a proxy if available if proxy: pluginfile = self.buildChromeExtension(proxy) options.add_extension(pluginfile) #Instantiate the driver #driver = WebDriver('bin/chromedriver',options=options, desired_capabilities=desired_capabilities) driver = webdriver.Remote(self.service.service_url, desired_capabilities=desired_capabilities, options=options) #Make webdriver = undefined script = ''' Object.defineProperty(navigator, 'webdriver', { get: () => undefined }) ''' driver.execute_script(script) if pluginfile: os.remove(pluginfile) pluginfile = None return driver except: self.console.exception() if pluginfile: os.remove(pluginfile) return None
def login_ui(console_url=None): """ Login to OpenShift Console Args: console_url (str): ocp console url return: driver (Selenium WebDriver) """ default_console = False if not console_url: console_url = get_ocp_url() default_console = True logger.info("Get password of OCP console") password = get_kubeadmin_password() password = password.rstrip() ocp_version = get_ocp_version() login_loc = locators[ocp_version]["login"] browser = ocsci_config.UI_SELENIUM.get("browser_type") if browser == "chrome": logger.info("chrome browser") chrome_options = Options() ignore_ssl = ocsci_config.UI_SELENIUM.get("ignore_ssl") if ignore_ssl: chrome_options.add_argument("--ignore-ssl-errors=yes") chrome_options.add_argument("--ignore-certificate-errors") chrome_options.add_argument("--allow-insecure-localhost") capabilities = chrome_options.to_capabilities() capabilities["acceptInsecureCerts"] = True # headless browsers are web browsers without a GUI headless = ocsci_config.UI_SELENIUM.get("headless") if headless: chrome_options.add_argument("--headless") chrome_options.add_argument("window-size=1920,1400") # use proxy server, if required if (config.DEPLOYMENT.get("proxy") or config.DEPLOYMENT.get("disconnected") ) and config.ENV_DATA.get("client_http_proxy"): client_proxy = urlparse(config.ENV_DATA.get("client_http_proxy")) # there is a big difference between configuring not authenticated # and authenticated proxy server for Chrome: # * not authenticated proxy can be configured via --proxy-server # command line parameter # * authenticated proxy have to be provided through customly # created Extension and it doesn't work in headless mode! if not client_proxy.username: # not authenticated proxy logger.info( f"Configuring not authenticated proxy ('{client_proxy.geturl()}') for browser" ) chrome_options.add_argument( f"--proxy-server={client_proxy.geturl()}") elif not headless: # authenticated proxy, not headless mode # create Chrome extension with proxy settings logger.info( f"Configuring authenticated proxy ('{client_proxy.geturl()}') for browser" ) _templating = Templating() manifest_json = _templating.render_template( constants.CHROME_PROXY_EXTENSION_MANIFEST_TEMPLATE, {}) background_js = _templating.render_template( constants.CHROME_PROXY_EXTENSION_BACKGROUND_TEMPLATE, {"proxy": client_proxy}, ) pluginfile = "/tmp/proxy_auth_plugin.zip" with zipfile.ZipFile(pluginfile, "w") as zp: zp.writestr("manifest.json", manifest_json) zp.writestr("background.js", background_js) chrome_options.add_extension(pluginfile) else: # authenticated proxy, headless mode logger.error( "It is not possible to configure authenticated proxy " f"('{client_proxy.geturl()}') for browser in headless mode" ) raise NotSupportedProxyConfiguration( "Unable to configure authenticated proxy in headless browser mode!" ) chrome_browser_type = ocsci_config.UI_SELENIUM.get("chrome_type") driver = webdriver.Chrome( ChromeDriverManager(chrome_type=chrome_browser_type).install(), options=chrome_options, ) else: raise ValueError(f"Not Support on {browser}") wait = WebDriverWait(driver, 60) driver.maximize_window() driver.get(console_url) if config.ENV_DATA["flexy_deployment"]: try: element = wait.until( ec.element_to_be_clickable((login_loc["flexy_kubeadmin"][1], login_loc["flexy_kubeadmin"][0]))) element.click() except TimeoutException as e: take_screenshot(driver) logger.error(e) element = wait.until( ec.element_to_be_clickable( (login_loc["username"][1], login_loc["username"][0]))) take_screenshot(driver) element.send_keys("kubeadmin") element = wait.until( ec.element_to_be_clickable( (login_loc["password"][1], login_loc["password"][0]))) element.send_keys(password) element = wait.until( ec.element_to_be_clickable( (login_loc["click_login"][1], login_loc["click_login"][0]))) element.click() if default_console: WebDriverWait(driver, 60).until(ec.title_is(login_loc["ocp_page"])) return driver
def get_chrome_driver_with_proxy(self, proxy_info, scheme='http', plugin_path=None): """Proxy Auth Extension args: proxy_host (str): domain or ip address, ie proxy.domain.com proxy_port (int): port proxy_username (str): auth username proxy_password (str): auth password kwargs: scheme (str): proxy scheme, default http plugin_path (str): absolute path of the extension return str -> plugin_path """ import string import zipfile if plugin_path is None: plugin_path = 'c://chrome_proxyauth_plugin.zip' manifest_json = """ { "version": "1.0.0", "manifest_version": 2, "name": "Chrome Proxy", "permissions": [ "proxy", "tabs", "unlimitedStorage", "storage", "<all_urls>", "webRequest", "webRequestBlocking" ], "background": { "scripts": ["background.js"] }, "minimum_chrome_version":"22.0.0" } """ background_js = string.Template( """ var config = { mode: "fixed_servers", rules: { singleProxy: { scheme: "${scheme}", host: "${host}", port: parseInt(${port}) }, bypassList: ["foobar.com"] } }; chrome.proxy.settings.set({value: config, scope: "regular"}, function() {}); function callbackFn(details) { return { authCredentials: { username: "******", password: "******" } }; } chrome.webRequest.onAuthRequired.addListener( callbackFn, {urls: ["<all_urls>"]}, ['blocking'] ); """ ).substitute( host=proxy_info['proxy_host'], port=proxy_info['proxy_port'], username=proxy_info.get('proxy_username', ''), password=proxy_info.get('proxy_password', ''), scheme=scheme, ) with zipfile.ZipFile(plugin_path, 'w') as zp: zp.writestr("manifest.json", manifest_json) zp.writestr("background.js", background_js) opts = Options() opts.add_argument("--start-maximized") # opts.add_argument("--headless") # opts.add_argument("--disable-gpu") opts.add_argument(self.ua) if 'proxy_username' in proxy_info and 'proxy_password' in proxy_info: opts.add_extension(plugin_path) else: opts.add_argument('--proxy-server=%s://%s:%d' % (scheme, proxy_info['proxy_host'], proxy_info['proxy_port'])) chrome_driver = os.path.abspath("./chromedriver.exe") browser = Chrome(chrome_driver, service_log_path=self.service_log_path, chrome_options=opts) self.logger.info('set proxy %s:%s source ip: %s type: %d', proxy_info['proxy_host'], proxy_info.get('proxy_username', ''), proxy_info['source_ip'], proxy_info['type']) return browser
import os import selenium.webdriver.support.ui as ui # Подключаем selenium (сперва установить через pip install selenium) 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 includes_path = "C:/Users/BRAXXMAN/source/repos/includes/" os.environ["webdriver.chrome.driver"] = includes_path + "chromedriver.exe" chrome_options = Options() chrome_options.add_extension(includes_path + 'Ghostery-–-Privacy-Ad-Blocker_v8.2.4.crx') # Перед инициализацией драйвера браузера удалим куки-файл, если он существует cookiesfile = "./DIRECTORYTOPROFILEFOLDERWITHINAPPDATA\Default\Cookies" if os.path.isfile(cookiesfile): os.remove(cookiesfile) else: ## Show an error ## print("Error: %s cookiesfile not found" % cookiesfile) # Сохраняет настройки расширений и браузера chrome_options.add_argument( "user-data-dir=DIRECTORYTOPROFILEFOLDERWITHINAPPDATA") driver = webdriver.Chrome(executable_path=includes_path + 'chromedriver.exe', chrome_options=chrome_options) #driver=webdriver.Firefox() # Переходим на страницу, на которой нужно что-то сделать driver.get('https://vk.com/') # Получаем указатель на поле ввода текста в форме постинга
def initialize_driver(headless=True, with_ublock=False, chromedriver_path=None): if not chromedriver_path: try: chromedriver_path = chromedriver_autoinstaller.install() except Exception as exception: log.critical( f"Failed to install the built-in chromedriver: {exception}\n" "download the correct version for your system at " "https://chromedriver.chromium.org/downloads and use the" "--chromedriver argument to point to the chromedriver executable" ) sys.exit() log.info(f"Initialising chromedriver at {chromedriver_path}...") chrome_options = Options() chrome_options.add_argument( "--disable-blink-features=AutomationControlled") chrome_options.add_experimental_option( "excludeSwitches", ["enable-automation", "enable-logging"]) chrome_options.add_experimental_option('useAutomationExtension', False) chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.accept_untrusted_certs = True chrome_options.assume_untrusted_cert_issuer = True chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--allow-http-screen-capture") chrome_options.add_argument("--disable-impl-side-painting") chrome_options.add_argument("--disable-setuid-sandbox") chrome_options.add_argument("--disable-seccomp-filter-sandbox") if headless: chrome_options.add_argument("--headless") chrome_options.add_argument("window-size=1920,1080") chrome_options.add_argument("--log-level=3") chrome_options.add_argument("--silent") chrome_options.add_argument("--disable-logging") # allows selenium to accept cookies with a non-int64 'expiry' value chrome_options.add_experimental_option("w3c", False) # removes the 'DevTools listening' log message chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"]) if with_ublock: chrome_options.add_extension( os.path.join(os.getcwd(), "bin", "ublock", "ublock-extension.crx")) logs_path = os.path.join(os.getcwd(), "logs") if not (os.path.isdir(logs_path)): os.makedirs(logs_path) driver = webdriver.Chrome( executable_path=chromedriver_path, service_log_path=os.path.join(logs_path, "webdrive.log"), # Don't verify self-signed cert, should help with 502 errors # (https://github.com/wkeeling/selenium-wire/issues/55) # seleniumwire_options={"verify_ssl": False}, options=chrome_options, ) if with_ublock: log.debug("Configuring uBlock") # set up uBlock driver.get( "chrome-extension://ilchdfhfciidacichehpmmjclkbfaecg/settings.html" ) # Un-hide the file upload button so we can use it element = driver.find_elements_by_class_name("hidden") driver.execute_script( "document.getElementsByClassName('hidden')[0].className = ''", element) # scroll down (for debugging) driver.execute_script("window.scrollTo(0, 2000)") uBlock_settings_file = str( os.path.join(os.getcwd(), "bin", "ublock", "ublock-settings.txt")) driver.find_element_by_id("restoreFilePicker").send_keys( uBlock_settings_file) try: WebDriverWait(driver, 3).until(EC.alert_is_present()) # click ok on pop up to accept overwrite driver.switch_to.alert.accept() except TimeoutException as ex: log.error("Timeout waiting for ublock config overwrite alert") # leave uBlock config driver.get("about:blank") return driver
chrome.proxy.settings.set({value: config, scope: "regular"}, function() {}); function callbackFn(details) { return { authCredentials: {username: "******", password: "******" } } } chrome.webRequest.onAuthRequired.addListener( callbackFn, {urls: ["<all_urls>"]}, ['blocking'] )""" % { 'ip': ip, 'port': port, 'username': username, 'password': password } plugin_file = 'proxy_auth_plugin.zip' with zipfile.ZipFile(plugin_file, 'w') as zp: zp.writestr('manifest.json', manifest_json) zp.writestr("background.js", background_js) chrome_options = Options() chrome_options.add_argument("--start-maximized") chrome_options.add_extension(plugin_file) browser = webdriver.Chrome(chrome_options=chrome_options) browser.get('http://httpbin.org/get')
#!/usr/bin/env python2.7 # -*- coding: utf-8 -*- from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_extension('extension.crx') driver = webdriver.Chrome(chrome_options=chrome_options) driver.get('http://stuff-dharrya.rhcloud.com/get_js_error') print(driver.execute_script('return window.JSErrorCollector_errors ? window.JSErrorCollector_errors.pump() : []')) driver.quit()
if len(sys.argv) > 1: executable_path = sys.argv[1] else: executable_path = "windows/chromedriver.exe" prefix = raw_input("file prefix:") adblock = raw_input("ad block on? [y or n] ") iterations = int(raw_input("number of iterations: ")) url = raw_input("url: ") os.environ["webdriver.chrome.driver"] = executable_path chrome_options = Options() adblockprefix = "AdBlockOff" if adblock == 'y': chrome_options.add_extension('AdBlock_v3.8.4.crx') adblockprefix = "AdBlockOn" driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options) driver.set_window_size(1280, 760) fName = prefix + "_" + adblockprefix + "_firstPaint_" + str(iterations) f2Name = prefix + "_" + adblockprefix + "_loadEventEnd_" + str(iterations) f = open(fName, 'w') f2 = open(f2Name, 'w') print "Test initiating, this can take a few seconds..." if adblock == 'y': driver.execute_script("window.close();") driver.switch_to_window(driver.window_handles[0])
# Include personal data document import Data # Chromedriver path chromedriver = "/usr/local/bin/chromedriver" # Set chromedriver as environmental parameter os.environ["webdriver.chrome.driver"] = chromedriver # Set the possibility to add a chrome extension chrome_options = Options() #Add the captchaClicker extension. Before do that, it is important to download the #extensions. To do so, paste the link on this site https://chrome-extension-downloader.com/ and download the #crx file chrome_options.add_extension('captchaClicker.crx') # Set the webdriver adding the path and the options (extensions) driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chrome_options) # Open the browser and navigate to packtPub page driver.get("https://www.packtpub.com/packt/offers/free-learning") try: # Find the login button on the page logInPackt = driver.find_element_by_link_text("Log in") # if nothing is found the NoSuchElementException is raised except selenium.common.exceptions.NoSuchElementException: print("User already logged in")
executable_path= r"C:\\Users\Administrator\Downloads\\instagram-auto-create-account_proxy-master\\instagram-auto-create-account_proxy-master\\geckodriver.exe" ) driver.install_addon(ext_path) configure_api_firefox() except: driver = webdriver.Firefox(firefox_profile=profile, executable_path=r"geckodriver.exe") driver.install_addon(ext_path) configure_api_firefox() if args.chrome: from selenium.webdriver.chrome.options import Options options = Options() options.add_argument("--lang=en") options.add_extension('anticaptcha.zip') options.add_argument(f'user-agent={userAgent}') try: driver = webdriver.Chrome( options=options, executable_path= r"C:\\Users\Administrator\Downloads\\instagram-auto-create-account_proxy-master\\instagram-auto-create-account_proxy-master\\chromedriver.exe" ) except: driver = webdriver.Chrome(options=options, executable_path=r"chromedriver.exe") driver.get("https://www.instagram.com/accounts/emailsignup/") time.sleep(8) name = account.username() #//button[text()='Accept']
import time import os from selenium import webdriver from selenium.webdriver.chrome.options import Options executable_path = "/Users/grow09/Desktop/parser/parser/chromedriver" os.environ["webdriver.chrome.driver"] = executable_path chrome_options = Options() # chrome_options.add_extension('/Users/grow09/Desktop/djangoprojects/shopenv/parser/parser/extension_1_17_21_0.crx') chrome_options.add_extension('/Users/grow09/Desktop/parser/parser/extension_2_2_1_0.crx') driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options) def logining(): driver.get("https://steamcommunity.com/login") login = driver.find_element_by_id("steamAccountName") login.send_keys("log") password = driver.find_element_by_id("steamPassword") password.send_keys("pass") steamlogin = driver.find_element_by_id("SteamLogin") steamlogin.click() time.sleep(15) def steambuy(): try: time.sleep(12) driver.get("") time.sleep(3) # code for SIH querys
import time from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait # This example requires Selenium WebDriver 3.13 or newer chrome_options = Options() # chrome_options.add_encoded_extension("gighmmpiobklfepjocnamgkkbiglidom") # chrome_options.add_argument("load-extension=/User/ljj/Library/Application Support/Google/Chrome/Default/Extensions/gighmmpiobklfepjocnamgkkbiglidom") chrome_options.add_extension("/Users/ljj/Documents/Courses/CS/LeetCode/Selenium-Scripts/OpenYoutubeEveryMorning/extension_4_25_1_0.crx") with webdriver.Chrome(options=chrome_options) as driver: wait = WebDriverWait(driver, 10) time.sleep(10) driver.switch_to.window(driver.window_handles[1]) driver.close() driver.switch_to.window(driver.window_handles[0]) driver.get("https://www.youtube.com/playlist?list=PL0tDb4jw6kPyN_Umwu7oZK44EFq-nvdwu") driver.find_element_by_css_selector("#content > a").click() time.sleep(60*15)
def initialize_driver(headless=True, with_ublock=False, chromedriver_path=None): if not chromedriver_path: try: chromedriver_path = chromedriver_autoinstaller.install() except Exception as exception: log.critical( f"Failed to install the built-in chromedriver: {exception}\n" "download the correct version for your system at " "https://chromedriver.chromium.org/downloads and use the" "--chromedriver argument to point to the chromedriver executable" ) sys.exit() log.info(f"Initialising chromedriver at {chromedriver_path}...") chrome_options = Options() if headless: chrome_options.add_argument("--headless") chrome_options.add_argument("window-size=1920,1080") chrome_options.add_argument("--log-level=3") chrome_options.add_argument("--silent") chrome_options.add_argument("--disable-logging") # allows selenium to accept cookies with a non-int64 'expiry' value chrome_options.add_experimental_option("w3c", False) # removes the 'DevTools listening' log message chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"]) # prevent Cloudflare from detecting ChromeDriver as bot chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"]) chrome_options.add_experimental_option("useAutomationExtension", False) chrome_options.add_argument( "--disable-blink-features=AutomationControlled") if with_ublock: chrome_options.add_extension( os.path.join(os.getcwd(), "bin", "ublock", "ublock-extension.crx")) logs_path = os.path.join(os.getcwd(), "logs") if not (os.path.isdir(logs_path)): os.makedirs(logs_path) driver = webdriver.Chrome( executable_path=chromedriver_path, service_log_path=os.path.join(logs_path, "webdrive.log"), # Don't verify self-signed cert, should help with 502 errors # (https://github.com/wkeeling/selenium-wire/issues/55) # seleniumwire_options={"verify_ssl": False}, options=chrome_options, ) driver.execute_cdp_cmd( "Network.setUserAgentOverride", { "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36" }, ) driver.execute_cdp_cmd( "Page.addScriptToEvaluateOnNewDocument", { "source": """ Object.defineProperty(navigator, 'webdriver', { get: () => undefined }) """ }, ) if with_ublock: log.debug("Configuring uBlock") # set up uBlock driver.get( "chrome-extension://ilchdfhfciidacichehpmmjclkbfaecg/settings.html" ) # Un-hide the file upload button so we can use it element = driver.find_elements_by_class_name("hidden") driver.execute_script( "document.getElementsByClassName('hidden')[0].className = ''", element) # scroll down (for debugging) driver.execute_script("window.scrollTo(0, 2000)") uBlock_settings_file = str( os.path.join(os.getcwd(), "bin", "ublock", "ublock-settings.txt")) driver.find_element_by_id("restoreFilePicker").send_keys( uBlock_settings_file) try: WebDriverWait(driver, 3).until(EC.alert_is_present()) # click ok on pop up to accept overwrite driver.switch_to.alert.accept() except TimeoutException: log.error("Timeout waiting for ublock config overwrite alert") # leave uBlock config driver.get("about:blank") return driver
current_space = '::' data = open('Links.txt', 'r').read() d_lines = data.splitlines() counts = 0 with open("Stamps.txt", "w") as text_file: text_file.write(str(counts)) for x in range(1, 4): for line in d_lines: if current_space not in line: if line.strip(): coun = random.choice(countries) print(coun) print(line) chrome_options = Options() chrome_options.add_experimental_option("detach", True) chrome_options.add_extension('8.0.4.0_0.crx') chrome_options.add_extension('4.1.2_0.crx') driver = webdriver.Chrome(options=chrome_options) driver.maximize_window() wait = WebDriverWait(driver, 3) presence = EC.presence_of_element_located visible = EC.visibility_of_element_located actions = webdriver.ActionChains(driver) print(driver.command_executor._url) print(driver.session_id) time.sleep(1) driver.get( "https://account.zenmate.com/en_US/login?redirectTo=/en_US/devices" ) driver.minimize_window() driver.maximize_window()
from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.chrome.options import Options from csv import reader from time import sleep from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.action_chains import ActionChains # import xlrd import csv chrome_options = Options() chrome_options.add_extension('snapaddy.crx.crx') driver = webdriver.Chrome( '/home/logicrays/Downloads/chromedriver', chrome_options=chrome_options) url = 'https://www.google.com' print('\nInitializing...') # driver= webdriver.Chrome() driver.implicitly_wait(2) driver.get(url) driver.implicitly_wait(3) sleep(3) # driver.fullscreen_window()
import time import getpass from sys import platform if platform == "linux" or platform == "linux2": # linux executable_path = 'chromedriver' elif platform == "win32": # Windows... executable_path = 'chromedriver.exe' username = str(raw_input("Enter the register no. : ")) password = getpass.getpass('Password : '******'ensuitego.crx') print("Opening browser window") driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options) driver.get("https://vtopbeta.vit.ac.in/vtop/") driver.find_element_by_css_selector('.btn-primary').click() driver.switch_to_window(driver.window_handles[1]) # LOGIN element = WebDriverWait(driver, 50).until( EC.presence_of_element_located((By.ID, "uname"))) elem = driver.find_element_by_xpath('//*[@id="uname"]') elem.clear() elem.send_keys(username)
if condition_function(): return True else: time.sleep(0.1) raise Exception('Timeout waiting for {}'.format(condition_function.__name__)) if __name__ == "__main__": # current working directory cwd = os.getcwd() # load adblock because ads block the articles. # THANKS MEDIA WALES, GREAT UX THERE chrome_options = Options() chrome_options.add_extension('adblockpluschrome.crx') # start a webbrowser driver = webdriver.Chrome(chrome_options=chrome_options) driver.implicitly_wait(5) driver.maximize_window() # go through all the search periods for week in dev_weeks: # convert start and end dates to required formats date_from = '%s %s' % (week['from'], start_day) date_to = '%s %s' % (week['to'], end_day) dt_from = datetime.strptime(date_from, "%Y-%m-%d %H:%M:%S") dt_from_str = '%sZ' % dt_from.isoformat()
options = Options() if browser_mode == 'headless': options.headless = True drivers_path = Path('drivers').resolve() extensions_path = Path('extensions').resolve() if browser_option == 'chrome': prefs = {"profile.managed_default_content_settings.images": 2} options.add_experimental_option("prefs", prefs) options.add_experimental_option('excludeSwitches', ['enable-logging']) if browser_mode == 'head': options.add_extension(str(extensions_path) + r"\extension_4_13_0_0.crx") browser = webdriver.Chrome(options = options, executable_path = str(drivers_path) + r"\chromedriver.exe") if browser_mode == 'head': browser.switch_to.window(browser.window_handles[1]) # options.add_argument('log-level=3') elif browser_option == 'firefox': browser = webdriver.Firefox(options = options, executable_path = str(drivers_path) + r"\geckodriver.exe", service_log_path = os.path.devnull) browser.install_addon(str(extensions_path) + r"\[email protected]") browser.install_addon(str(extensions_path) + r"\@easyimageblocker.xpi") if comic_url == 'None': comic_name = json_object.get('f_comic_name') year = int(json_object.get('f_year'))
'queue_name': 'bdd' } #config settings for each category for url , table, type mapping catmap = { 'PrimaryWeapon': {'url': 'weapon', 'table': 'Weapon', 'type': 'primary_weapon'}, 'SecondaryWeapon': {'url': 'subweapon', 'table': 'Weapon', 'type': 'secondary_weapon'}, 'Fish': {'url': 'items/fish', 'table': 'MainItem', 'type': 'seafood'}, 'ProdRecipes': {'url': 'designs', 'table': 'Recipes', 'type': 'production'}, 'CookingRecipes': {'url': 'recipes/culinary', 'table': 'Recipes', 'type': 'cooking'} } #setup ublock origin adblocker cuz BDDatabase is horribly full of ads/adware chrome_options = Options() chrome_options.add_extension('ublock-origin_1_6_8.crx') #language of site lang = 'us' #set up the data dumper style output for debuggins pp = pprint.PrettyPrinter(indent=4) #debug print function so final version is more quiet :) def dp(message): global appcfg if appcfg['debug']: print message def parse_icon_mats(mats):
def setUpClass(cls): chrome_options = Options() chrome_options.add_extension('../extension.crx') cls._driver = webdriver.Chrome(chrome_options=chrome_options)
from companynames import bseNames from companynames import nseNames from selenium import webdriver from selenium.webdriver.chrome.options import Options import time import datetime import json from selenium.webdriver.common.keys import Keys start_time = time.clock() chrome_options = Options() chrome_options.add_extension('extension_1_12_1.crx') # chrome_options.add_argument('--disk-cache-dir=C:/Users/Kashyap/AppData/Local/Google/Chrome/User Data/Default/Cache') chrome_options.add_argument("user-data-dir=C:/Users/Kashyap/AppData/Local/Google/Chrome/User Data/dumdefault") driver = webdriver.Chrome(chrome_options=chrome_options) # webdriver.PhantomJS('./phantomjs-2.1.1-windows/bin/phantomjs', service_args=['--load-images=no']) today_date = datetime.date.today().strftime("%d%m%Y") x = 1 test_number = 1 def testforbse(p, q): global test_number global x print("Test %s" % test_number, "running") for name in bseNames[p:q]: company_name = name
def set_selenium_local_session(proxy_address, proxy_port, proxy_chrome_extension, headless_browser, use_firefox, browser_profile_path, disable_image_load, page_delay, logger): """Starts local session for a selenium server. Default case scenario.""" browser = None err_msg = '' if use_firefox: firefox_options = Firefox_Options() if headless_browser: firefox_options.add_argument('-headless') if browser_profile_path is not None: firefox_profile = webdriver.FirefoxProfile(browser_profile_path) else: firefox_profile = webdriver.FirefoxProfile() if disable_image_load: # permissions.default.image = 2: Disable images load, # this setting can improve pageload & save bandwidth firefox_profile.set_preference('permissions.default.image', 2) if proxy_address and proxy_port: firefox_profile.set_preference('network.proxy.type', 1) firefox_profile.set_preference('network.proxy.http', proxy_address) firefox_profile.set_preference('network.proxy.http_port', proxy_port) firefox_profile.set_preference('network.proxy.ssl', proxy_address) firefox_profile.set_preference('network.proxy.ssl_port', proxy_port) browser = webdriver.Firefox(firefox_profile=firefox_profile, options=firefox_options) else: chromedriver_location = Settings.chromedriver_location chrome_options = Options() chrome_options.add_argument("--mute-audio") chrome_options.add_argument('--dns-prefetch-disable') chrome_options.add_argument('--lang=en-US') chrome_options.add_argument('--disable-setuid-sandbox') # this option implements Chrome Headless, a new (late 2017) # GUI-less browser. chromedriver 2.9 and above required if headless_browser: chrome_options.add_argument('--headless') chrome_options.add_argument('--no-sandbox') if disable_image_load: chrome_options.add_argument( '--blink-settings=imagesEnabled=false') # replaces browser User Agent from "HeadlessChrome". user_agent = "Chrome" chrome_options.add_argument( 'user-agent={user_agent}'.format(user_agent=user_agent)) capabilities = DesiredCapabilities.CHROME # Proxy for chrome if proxy_address and proxy_port: prox = Proxy() proxy = ":".join([proxy_address, str(proxy_port)]) if headless_browser: chrome_options.add_argument( "--proxy-server=http://{}".format(proxy)) else: prox.proxy_type = ProxyType.MANUAL prox.http_proxy = proxy prox.socks_proxy = proxy prox.ssl_proxy = proxy prox.add_to_capabilities(capabilities) # add proxy extension if proxy_chrome_extension and not headless_browser: chrome_options.add_extension(proxy_chrome_extension) # using saved profile for chrome if browser_profile_path is not None: chrome_options.add_argument( 'user-data-dir={}'.format(browser_profile_path)) chrome_prefs = { 'intl.accept_languages': 'en-US', } if disable_image_load: chrome_prefs['profile.managed_default_content_settings.images'] = 2 chrome_options.add_experimental_option('prefs', chrome_prefs) try: browser = webdriver.Chrome(chromedriver_location, desired_capabilities=capabilities, chrome_options=chrome_options) except WebDriverException as exc: logger.exception(exc) err_msg = 'ensure chromedriver is installed at {}'.format( Settings.chromedriver_location) return browser, err_msg # prevent: Message: unknown error: call function result missing 'value' matches = re.match( r'^(\d+\.\d+)', browser.capabilities['chrome']['chromedriverVersion']) if float(matches.groups()[0]) < Settings.chromedriver_min_version: err_msg = 'chromedriver {} is not supported, expects {}+'.format( float(matches.groups()[0]), Settings.chromedriver_min_version) return browser, err_msg browser.implicitly_wait(page_delay) message = "Session started!" highlight_print('browser', message, "initialization", "info", logger) print('') return browser, err_msg
# put extension into zip file and place inside of folder pluginfile = 'proxy_auth_plugin.zip' snkrsExtendo = 'snkrs.zip' with zipfile.ZipFile(pluginfile, 'w') as zp: zp.writestr("manifest.json", manifest_json_proxy) zp.writestr("background.js", background_js_proxy) with zipfile.ZipFile(snkrsExtendo, 'w') as snkZp: snkZp.writestr("manifest.json", manifest_json_snkrs) snkZp.writestr("snkrsLogin.js", snkrsLogin_js_snkrs) snkZp.writestr("redirect.js", redirect_js_snkrs) co = Options() co.add_argument("--start-maximized") co.add_extension(pluginfile) co.add_extension(snkrsExtendo) driver = webdriver.Chrome(options=co) driver.get(proceedTo) print("Browser " + str(count) + " fully loaded") # print(count) # print(browserCount) if count == int(browserCount): break if count == int(browserCount): break userStop = input("\nAll windows have loaded.\n"
def my_proxy(PROXY_HOST,PROXY_PORT, username, password): if username: manifest_json = """ { "version": "1.0.0", "manifest_version": 2, "name": "Chrome Proxy", "permissions": [ "proxy", "tabs", "unlimitedStorage", "storage", "<all_urls>", "webRequest", "webRequestBlocking" ], "background": { "scripts": ["background.js"] }, "minimum_chrome_version":"22.0.0" } """ background_js = """ var config = { mode: "fixed_servers", rules: { singleProxy: { scheme: "http", host: '%s', port: parseInt('%s') }, bypassList: ["foobar.com"] } }; chrome.proxy.settings.set({value: config, scope: "regular"}, function() {}); function callbackFn(details) { return { authCredentials: { username: '******', password: '******' } }; } chrome.webRequest.onAuthRequired.addListener( callbackFn, {urls: ["<all_urls>"]}, ['blocking'] ); """% (PROXY_HOST, PROXY_PORT, username, password) pluginfile = 'proxy_auth_plugin.zip' with zipfile.ZipFile(pluginfile, 'w') as zp: zp.writestr("manifest.json", manifest_json) zp.writestr("background.js", background_js) co = Options() co.add_argument("--incognito") co.add_extension(pluginfile) else: co = webdriver.ChromeOptions() co.add_argument('--proxy-server=%s' % PROXY_HOST+":"+PROXY_PORT) co.add_argument('--disable-gpu') co.add_argument('--log-level=3') co.add_argument("--incognito") co.add_argument('--window-size=880x880') #co.add_argument('--headless') co.add_experimental_option("prefs", {"profile.managed_default_content_settings.images":2}) driver = webdriver.Chrome(chrome_options=co) return driver
def start_driver(self): cdpath = 'C:\\Users\\anon\\Desktop\\schlong\\chromedriver.exe' copt = Options() copt.add_extension('C:\\Users\\anon\\Desktop\\schlong\\uBlock.crx') self.driver = webdriver.Chrome(executable_path=cdpath,chrome_options=copt) lg.info('Started chromedriver')
# Importing packages from selenium.common.exceptions import NoSuchElementException import csv import pandas as pd import time from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.support.select import Select import os.path chrome_options = Options() chrome_options.add_extension('Extensions\Adblock-Plus-free-ad-blocker_v3.8.0.crx') chrome_options.add_argument('--disable-user-media-security') driver = webdriver.Chrome(chrome_options=chrome_options) league_urls = [] count_start = 0 count_end = 0 league_urls.append('https://www.whoscored.com/Regions/206/Tournaments/4/Spain-La-Liga') league_urls.append('https://www.whoscored.com/Regions/252/Tournaments/2/England-Premier-League') league_urls.append('https://www.whoscored.com/Regions/108/Tournaments/5/Italy-Serie-A') league_urls.append('https://www.whoscored.com/Regions/81/Tournaments/3/Germany-Bundesliga') league_urls.append('https://www.whoscored.com/Regions/74/Tournaments/22/France-Ligue-1') league_urls.append('https://www.whoscored.com/Regions/155/Tournaments/13/Netherlands-Eredivisie') def bypass_cookie_request():
graph_database_location = "http://"+database+":7474/db/data/" graph = Graph(graph_database_location, user='******', password='******') # connect to the local graph database if delete_graph_history == "yes": graph.delete_all() # Delete all the previous made nodes and relationship print("DATABASE DELETED !") 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=[]
zp.writestr("manifest.json", manifest_json) zp.writestr("background.js", background_js) return pluginfile if __name__ == "__main__": if file_type == 'sqllite': if path.exists(sql_db_name) is False: conn = create_connection(sql_db_name) else: conn = sqlite3.connect(sql_db_name) products = {} co = Options() if proxy is not None: pluginfile = proxy_extension(proxy) co.add_extension(pluginfile) co.add_argument("--mute-audio") #co.add_extension(r'UBLOCK.crx') driver = webdriver.Chrome(options=co) driver.get('https://google.com/') driver.execute_script('''window.open("https://www.walmart.com/","_blank");''') time.sleep(5) driver.close() time.sleep(1) driver.switch_to.window(driver.window_handles[0]) time.sleep(5) driver_captcha_support(driver,walmart_start_page) time.sleep(5) page_numbers = driver.find_element_by_xpath('//*[@id="mainSearchContent"]/div[3]/div[2]/ul/li[8]/a').text print(str(page_numbers) + " pages to scrape.")
from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.options import Options from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait import time options = Options() options.add_extension('extension_0_71_0_0.crx') driver = webdriver.Chrome(ChromeDriverManager().install(), options=options) driver.maximize_window() class SetupTela6: def __init__(self): pass def access(self): driver.get( 'https://americaenergia.powerhub.io/america-energia/usuarios/criar' ) def accessIframe(self): driver.switch_to.parent_frame() def login(self): self.accessIframe() login = WebDriverWait(driver, 10).until( EC.presence_of_element_located( (By.XPATH, "//input[@type='email']")))
from selenium.webdriver.common.by import By import time import pyautogui as pg from selenium.webdriver.support.ui import Select #email = input('Please enter your email: ') #password = input('Please enter your password: '******'Object Oriented Programming in Java Specialization' # pls enter your course name cookie_file = open( 'cookies.txt') # account cookies should be saved with same name cookie = cookie_file.read() cookie_file.close() options = Options() options.add_extension("/usr/bin/extension_1_5_0_0.crx") driver = webdriver.Chrome(executable_path="/usr/bin/chromedriver", options=options) # opens the chrome browser #driver = webdriver.Chrome(options=options) def coursera(): driver.maximize_window() # a timer for all the commands to keep things smooth driver.implicitly_wait(10) # open coursera driver.get("https://www.coursera.org") # opens the webpage time.sleep(3) print("time to add cookie")
captcha_url = 'https://vtop.vit.ac.in/student/captcha.asp' submit_url = 'https://vtop.vit.ac.in/student/stud_login_submit.asp' timetable_url = 'https://vtop.vit.ac.in/student/course_regular.asp?sem=FS' home_url = 'https://vtop.vit.ac.in/student/stud_home.asp' course_page_url = 'https://vtop.vit.ac.in/student/coursepage_plan_view.asp?sem=FS' course_contents_url = 'https://vtop.vit.ac.in/student/coursepage_view3.asp' marks_url = 'https://vtop.vit.ac.in/student/marks.asp?sem=WS' head_url = 'https://vtop.vit.ac.in/student' pattern = r'(FALL|WIN|SUM){1}SEM[0-9]{4}-[0-9]{2}_CP[0-9]{4}.*_[A-Z]{2,4}[0-9]{2}_' req = requests.Session() req.mount('http://vtop.vit.ac.in', HTTPAdapter(max_retries=10)) requests.packages.urllib3.disable_warnings() executable_path = "C:/chromedriver" os.environ["webdriver.chrome.driver"] = executable_path chrome_options = Options() chrome_options.add_extension('autocaptcha-for-chrome.crx') driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options) class Api: def __init__(self, regno, pwd, gui = None, folder = None): self.regno = regno self.pwd = pwd self.gui = gui self.folder = folder def set_folder(self, folder): self.folder = folder def login(self): print "Loggin in" driver.get('https://vtop.vit.ac.in/student/stud_login.asp') time.sleep(0.5) # Let the user actually see something! regno_el = driver.find_element_by_name('regno')
def start_driver(): opts = Options() opts.add_extension(get_extension_path()) opts.add_experimental_option("prefs", {"profile.block_third_party_cookies": False}) opts.add_argument('--dns-prefetch-disable') return webdriver.Chrome(config.CHROMEDRIVER_PATH, chrome_options=opts)
examples2 = [ "http://www.pinterest.com/search/pins/?q=pencil", "http://en.m.wikipedia.org/wiki/Nuon_Chea", "http://en.wikipedia.org/wiki/Category:Brand_name_materials", "http://en.wikipedia.org/wiki/Category:Theoretical_physicists", "http://en.wikipedia.org/wiki/Type_system", "http://en.wikipedia.org/wiki/Velcro", ] d = DesiredCapabilities.CHROME d["loggingPrefs"] = {"browser": "ALL"} extLoc = "C:/Users/Kade/git/bigsemantics/ExtractionExtension/extractionExtension.crx" chrome_options = Options() chrome_options.add_extension(extLoc) driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=d) fileHit = open("jsonClientSide.txt", "w") countFound = 0 for example in examples: driver.get(example) time.sleep(4) for entry in driver.get_log("browser"): if "source" in entry: if entry["source"] == "console-api" and "chrome-extension" in entry["message"]: fileHit.write(entry["message"][72:].encode("utf-8") + "\n\n") countFound += 1
#!/usr/bin/env python2.7 # -*- coding: utf-8 -*- from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_extension('extension-js-console-collector.crx') driver = webdriver.Chrome(chrome_options=chrome_options) driver.get('http://google.com') driver.execute_script('console.log("testing 1")') driver.execute_script('console.log("testing 2")') print(driver.execute_script('return window.JSConsoleCollector ? window.JSConsoleCollector.pump() : []')) driver.quit()