def open_browser(env, browser='chrome'): driver = None if browser == "chrome": chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--incognito') driver = webdriver.Chrome(executable_path=chrome_driver_path, chrome_options=chrome_options) if browser == "msedge": edge_options = EdgeOptions() edge_options.use_chromium = True edge_options.add_argument('-inprivate') driver = Edge(executable_path=msedge_driver_path, options=edge_options) if browser == "firefox": firefox_options = webdriver.FirefoxOptions() firefox_options.add_argument('--incognito') driver = webdriver.Firefox(executable_path=firefox_driver_path, options=firefox_options) elif browser == "ie": driver = webdriver.Ie(executable_path=ie_driver_path) # selenium grid # driver = webdriver.Remote(command_executor='http://10.22.40.234:5555/wd/hub', # desired_capabilities=DesiredCapabilities.INTERNETEXPLORER) # 获取web配置 with open(web_config_path, 'r', encoding='utf-8') as file: data = yaml.load(file, Loader=yaml.FullLoader) # 以下是一个示例,基于config/web_config.yaml文件做的配置 if env == "msit": url = data["portal"]['msit'] Logger.info("Open Url: %s", url) driver.get(url) if env == "srol1": url = data["portal"]['srol1'] Logger.info("Open Url: %s", url) driver.get(url) if env == "srol2": url = data["portal"]['srol2'] Logger.info("Open Url: %s", url) driver.get(url) if env == "ppe": url = data["portal"]['ppe'] Logger.info("Open Url: %s", url) driver.get(url) if env == "refe": url = data["portal"]['refe'] Logger.info("Open Url: %s", url) driver.get(url) elif env == '': driver = None driver.maximize_window() driver.implicitly_wait(data['implicitly_wait']) return driver
def info(self): options = EdgeOptions() options.use_chromium = True #options.add_argument('--start-maximized') options.add_argument('--disable-extensions') driver_path = 'Driver\\msedgedriver.exe' #Opciones de navegacion driver = Edge(executable_path=driver_path, options=options) #inicializamos el navegador driver.get('https://www.accuweather.com/') Departamento = "Paysandú" #COOKIES WebDriverWait(driver, 10)\ .until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div[9]/div/div')))\ .click() #BUSCADOR WebDriverWait(driver, 10)\ .until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div[1]/div[2]/div[1]/form/input')))\ .send_keys(Departamento) #CIUDAD WebDriverWait(driver, 10)\ .until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div[1]/div[2]/div[2]/div[2]/div')))\ .click() #DIAS WebDriverWait(driver, 10)\ .until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div[3]/div/div[3]/a[3]')))\ .click() card = WebDriverWait(driver, 20)\ .until(EC.frame_to_be_available_and_switch_to_it((By.NAME, "google_ads_iframe_/6581/web/sam/interstitial/weather/local_home_0"))) if (card): WebDriverWait(driver, 10)\ .until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/div[1]/div[1]"))).click() #INFO WebDriverWait(driver, 10)\ .until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/div[1]/div[1]/div'))) info_clima = driver.find_element_by_xpath( '/html/body/div/div[5]/div[1]/div[1]') info_clima = info_clima.text titulo = driver.find_element_by_css_selector('p.module-title') titulo = titulo.text #print(titulo) #SEPARAR datos_semana = info_clima.split(titulo)[1].split('\n')[1:36] driver.quit() return datos_semana
def get_local_driver(browser_name, headless, locale_code, servername, proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent, disable_csp, enable_ws, enable_sync, use_auto_ext, no_sandbox, disable_gpu, incognito, guest_mode, devtools, swiftshader, block_images, user_data_dir, extension_zip, extension_dir, mobile_emulator, device_width, device_height, device_pixel_ratio): ''' Spins up a new web browser and returns the driver. Can also be used to spin up additional browsers for the same test. ''' downloads_path = download_helper.get_downloads_folder() download_helper.reset_downloads_folder() if browser_name == constants.Browser.FIREFOX: try: try: # Use Geckodriver for Firefox if it's on the PATH profile = _create_firefox_profile(downloads_path, locale_code, proxy_string, user_agent, disable_csp) firefox_capabilities = DesiredCapabilities.FIREFOX.copy() firefox_capabilities['marionette'] = True options = webdriver.FirefoxOptions() if headless: options.add_argument('-headless') firefox_capabilities['moz:firefoxOptions'] = ({ 'args': ['-headless'] }) if LOCAL_GECKODRIVER and os.path.exists(LOCAL_GECKODRIVER): try: make_driver_executable_if_not(LOCAL_GECKODRIVER) except Exception as e: logging.debug("\nWarning: Could not make geckodriver" " executable: %s" % e) elif not is_geckodriver_on_path(): args = " ".join(sys.argv) if not ("-n" in sys.argv or "-n=" in args or args == "-c"): # (Not multithreaded) from seleniumbase.console_scripts import sb_install sys_args = sys.argv # Save a copy of current sys args print("\nWarning: geckodriver not found!" " Installing now:") try: sb_install.main(override="geckodriver") except Exception as e: print("\nWarning: Could not install geckodriver: " "%s" % e) sys.argv = sys_args # Put back the original sys args if "linux" in PLATFORM or not headless: firefox_driver = webdriver.Firefox( firefox_profile=profile, capabilities=firefox_capabilities) else: firefox_driver = webdriver.Firefox( firefox_profile=profile, capabilities=firefox_capabilities, options=options) except Exception: profile = _create_firefox_profile(downloads_path, locale_code, proxy_string, user_agent, disable_csp) firefox_capabilities = DesiredCapabilities.FIREFOX.copy() firefox_driver = webdriver.Firefox( firefox_profile=profile, capabilities=firefox_capabilities) return firefox_driver except Exception as e: if headless: raise Exception(e) return webdriver.Firefox() elif browser_name == constants.Browser.INTERNET_EXPLORER: if not IS_WINDOWS: raise Exception( "IE Browser is for Windows-based operating systems only!") from selenium.webdriver.ie.options import Options ie_options = Options() ie_options.ignore_protected_mode_settings = False ie_options.ignore_zoom_level = True ie_options.require_window_focus = False ie_options.native_events = True ie_options.full_page_screenshot = True ie_options.persistent_hover = True ie_capabilities = ie_options.to_capabilities() if LOCAL_IEDRIVER and os.path.exists(LOCAL_IEDRIVER): try: make_driver_executable_if_not(LOCAL_IEDRIVER) except Exception as e: logging.debug("\nWarning: Could not make iedriver" " executable: %s" % e) return webdriver.Ie(capabilities=ie_capabilities) elif browser_name == constants.Browser.EDGE: try: chrome_options = _set_chrome_options( browser_name, downloads_path, headless, locale_code, proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent, disable_csp, enable_ws, enable_sync, use_auto_ext, no_sandbox, disable_gpu, incognito, guest_mode, devtools, swiftshader, block_images, user_data_dir, extension_zip, extension_dir, servername, mobile_emulator, device_width, device_height, device_pixel_ratio) if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER): try: make_driver_executable_if_not(LOCAL_EDGEDRIVER) except Exception as e: logging.debug("\nWarning: Could not make edgedriver" " executable: %s" % e) elif not is_edgedriver_on_path(): args = " ".join(sys.argv) if not ("-n" in sys.argv or "-n=" in args or args == "-c"): # (Not multithreaded) from seleniumbase.console_scripts import sb_install sys_args = sys.argv # Save a copy of current sys args print("\nWarning: msedgedriver not found. Installing now:") sb_install.main(override="edgedriver") sys.argv = sys_args # Put back the original sys args # For Microsoft Edge (Chromium) version 79 or lower return webdriver.Chrome(executable_path=LOCAL_EDGEDRIVER, options=chrome_options) except Exception: # For Microsoft Edge (Chromium) version 80 or higher from msedge.selenium_tools import Edge, EdgeOptions if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER): try: make_driver_executable_if_not(LOCAL_EDGEDRIVER) except Exception as e: logging.debug("\nWarning: Could not make edgedriver" " executable: %s" % e) edge_options = EdgeOptions() edge_options.use_chromium = True prefs = { "download.default_directory": downloads_path, "local_discovery.notifications_enabled": False, "credentials_enable_service": False, "download.prompt_for_download": False, "download.directory_upgrade": True, "safebrowsing.enabled": False, "safebrowsing.disable_download_protection": True, "profile": { "password_manager_enabled": False, "default_content_setting_values.automatic_downloads": 1 } } if locale_code: prefs["intl.accept_languages"] = locale_code if block_images: prefs["profile.managed_default_content_settings.images"] = 2 edge_options.add_experimental_option("prefs", prefs) edge_options.add_experimental_option("w3c", True) edge_options.add_experimental_option("useAutomationExtension", False) edge_options.add_experimental_option( "excludeSwitches", ["enable-automation", "enable-logging"]) if guest_mode: edge_options.add_argument("--guest") if headless: edge_options.add_argument("--headless") if mobile_emulator: emulator_settings = {} device_metrics = {} if type(device_width) is int and ( type(device_height) is int and (type(device_pixel_ratio) is int)): device_metrics["width"] = device_width device_metrics["height"] = device_height device_metrics["pixelRatio"] = device_pixel_ratio else: device_metrics["width"] = 411 device_metrics["height"] = 731 device_metrics["pixelRatio"] = 3 emulator_settings["deviceMetrics"] = device_metrics if user_agent: emulator_settings["userAgent"] = user_agent edge_options.add_experimental_option("mobileEmulation", emulator_settings) edge_options.add_argument("--enable-sync") edge_options.add_argument("--disable-infobars") edge_options.add_argument("--disable-save-password-bubble") edge_options.add_argument("--disable-single-click-autofill") edge_options.add_argument( "--disable-autofill-keyboard-accessory-view[8]") edge_options.add_argument("--disable-translate") if not enable_ws: edge_options.add_argument("--disable-web-security") edge_options.add_argument("--homepage=about:blank") edge_options.add_argument("--dns-prefetch-disable") edge_options.add_argument("--dom-automation") edge_options.add_argument("--disable-hang-monitor") edge_options.add_argument("--disable-prompt-on-repost") if proxy_string: edge_options.add_argument('--proxy-server=%s' % proxy_string) edge_options.add_argument("--test-type") edge_options.add_argument("--log-level=3") edge_options.add_argument("--no-first-run") edge_options.add_argument("--ignore-certificate-errors") if devtools and not headless: edge_options.add_argument("--auto-open-devtools-for-tabs") edge_options.add_argument("--allow-file-access-from-files") edge_options.add_argument("--allow-insecure-localhost") edge_options.add_argument("--allow-running-insecure-content") if user_agent: edge_options.add_argument("--user-agent=%s" % user_agent) edge_options.add_argument("--no-sandbox") if swiftshader: edge_options.add_argument("--use-gl=swiftshader") else: edge_options.add_argument("--disable-gpu") if "linux" in PLATFORM: edge_options.add_argument("--disable-dev-shm-usage") capabilities = edge_options.to_capabilities() capabilities["platform"] = '' return Edge(executable_path=LOCAL_EDGEDRIVER, capabilities=capabilities) elif browser_name == constants.Browser.SAFARI: arg_join = " ".join(sys.argv) if ("-n" in sys.argv) or ("-n=" in arg_join) or (arg_join == "-c"): # Skip if multithreaded raise Exception("Can't run Safari tests in multi-threaded mode!") safari_capabilities = _set_safari_capabilities() return webdriver.Safari(desired_capabilities=safari_capabilities) elif browser_name == constants.Browser.OPERA: try: if LOCAL_OPERADRIVER and os.path.exists(LOCAL_OPERADRIVER): try: make_driver_executable_if_not(LOCAL_OPERADRIVER) except Exception as e: logging.debug("\nWarning: Could not make operadriver" " executable: %s" % e) opera_options = _set_chrome_options( browser_name, downloads_path, headless, locale_code, proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent, disable_csp, enable_ws, enable_sync, use_auto_ext, no_sandbox, disable_gpu, incognito, guest_mode, devtools, swiftshader, block_images, user_data_dir, extension_zip, extension_dir, servername, mobile_emulator, device_width, device_height, device_pixel_ratio) opera_options.headless = False # No support for headless Opera return webdriver.Opera(options=opera_options) except Exception: return webdriver.Opera() elif browser_name == constants.Browser.PHANTOM_JS: with warnings.catch_warnings(): # Ignore "PhantomJS has been deprecated" UserWarning warnings.simplefilter("ignore", category=UserWarning) return webdriver.PhantomJS() elif browser_name == constants.Browser.GOOGLE_CHROME: try: chrome_options = _set_chrome_options( browser_name, downloads_path, headless, locale_code, proxy_string, proxy_auth, proxy_user, proxy_pass, user_agent, disable_csp, enable_ws, enable_sync, use_auto_ext, no_sandbox, disable_gpu, incognito, guest_mode, devtools, swiftshader, block_images, user_data_dir, extension_zip, extension_dir, servername, mobile_emulator, device_width, device_height, device_pixel_ratio) if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER): try: make_driver_executable_if_not(LOCAL_CHROMEDRIVER) except Exception as e: logging.debug("\nWarning: Could not make chromedriver" " executable: %s" % e) elif not is_chromedriver_on_path(): args = " ".join(sys.argv) if not ("-n" in sys.argv or "-n=" in args or args == "-c"): # (Not multithreaded) from seleniumbase.console_scripts import sb_install sys_args = sys.argv # Save a copy of current sys args print("\nWarning: chromedriver not found. Installing now:") sb_install.main(override="chromedriver") sys.argv = sys_args # Put back the original sys args if not headless or "linux" not in PLATFORM: return webdriver.Chrome(options=chrome_options) else: # Running headless on Linux try: return webdriver.Chrome(options=chrome_options) except Exception: # Use the virtual display on Linux during headless errors logging.debug("\nWarning: Chrome failed to launch in" " headless mode. Attempting to use the" " SeleniumBase virtual display on Linux...") chrome_options.headless = False return webdriver.Chrome(options=chrome_options) except Exception as e: if headless: raise Exception(e) if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER): try: make_driver_executable_if_not(LOCAL_CHROMEDRIVER) except Exception as e: logging.debug("\nWarning: Could not make chromedriver" " executable: %s" % e) return webdriver.Chrome() else: raise Exception("%s is not a valid browser option for this system!" % browser_name)
Simple generic script that automates the Edge browser on a windows machine to navigate to a page The URL of the page to naviage must be passed in parameters Usage: python Edge-open-url-generic.py "https://your-fqdn/your-path" """ import sys, time # Configure Selenium from msedge.selenium_tools import Edge, EdgeOptions, EdgeService MSEDGEDRIVER_PATH = "C:\\edgedriver_win64\\msedgedriver.exe" DEFAULT_URL = "https://www.riverbed.com" if __name__ == "__main__": service = EdgeService(MSEDGEDRIVER_PATH) options = EdgeOptions() options.use_chromium = True driver = Edge(executable_path=MSEDGEDRIVER_PATH, options=options) # Synthetic test url = DEFAULT_URL if (len(sys.argv) > 1): url = sys.argv[1] driver.get(url) time.sleep(5) driver.close() driver.quit()
from time import sleep from datetime import datetime from openpyxl import Workbook import csv game_id = #enter your game ID here #you can alter the URL as you like,here I have set it accordingly so that I can get all the positive reviews in all the language template = 'https://steamcommunity.com/app/{}/positivereviews/?browsefilter=toprated&p=1&filterLanguage=all' template_with_language = 'https://steamcommunity.com/app/{}/positivereviews/?browsefilter=toprated&p=1&filterLanguage=all' url = template_with_language.format(game_id) # setup driver options = EdgeOptions() options.use_chromium = True driver = Edge(options=options) driver.maximize_window() driver.get(url) # get current position of y scrollbar last_position = driver.execute_script("return window.pageYOffset;") reviews = [] review_ids = set() running = True while running: # get cards on the page cards = driver.find_elements_by_class_name('apphub_Card')
from msedge.selenium_tools import EdgeOptions import time import random options = EdgeOptions() options.use_chromium = True options.add_argument("headless") # options.add_argument("disable-gpu") options.add_argument("--disable-blink-features") options.add_argument("--disable-blink-features=AutomationControlled") options.add_argument("start-maximized") options.add_experimental_option("excludeSwitches", ["enable-automation"]) options.add_experimental_option("useAutomationExtension", False) msedge = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedgedriver.exe" driver = Edge(options=options, executable_path=msedge) script = "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})" driver.execute_script(script) url = "https://www.deciphergenomics.org/genes" driver.get(url) print("网址:", url) # 等待加载 time.sleep(40) # 定位下拉选择框并选择100 driver.find_element_by_xpath( '//*[@id="content"]/div/div/div[2]/div/div/div[2]/div/div[1]/div/label/select/option[@value="100"]' ).click() time.sleep(10)
def scrape(secure=False): options = EdgeOptions() options.use_chromium = True driver = Edge(options=options) query = input("▁ ▂ ▄ ▅ ▆ ▇ █ 𝐄𝐧𝐭𝐞𝐫 𝐭𝐡𝐞 𝐓𝐞𝐱𝐭 𝐭𝐨 𝐬𝐞𝐚𝐫𝐜𝐡 █ ▇ ▆ ▅ ▄ ▂ ▁\n\n ") print("\n𝘚𝘵𝘢𝘳𝘵𝘦𝘥 𝘚𝘤𝘳𝘢𝘱𝘪𝘯𝘨 ↦↦↦↦↦↦↦↦↦↦") print("\nPlease Wait ............\n") driver.get("https://www.twitter.com/login") driver.maximize_window() username = driver.find_element_by_xpath( '//input[@name="session[username_or_email]"]') username.send_keys("*****@*****.**") #password=getpass() userpas = driver.find_element_by_xpath( '//input[@name="session[password]"]') userpas.send_keys('-----') userpas.send_keys(Keys.RETURN) sleep(2) if secure: username = driver.find_element_by_xpath( '//input[@name="session[username_or_email]"]') username.send_keys("031-----") userpas = driver.find_element_by_xpath( '//input[@name="session[password]"]') userpas.send_keys('----') userpas.send_keys(Keys.RETURN) sleep(2) search = driver.find_element_by_xpath( '//input[@aria-label="Search query"]') search.send_keys('"پاک فوج" lang:ur -filter:links filter:replies') search.send_keys(Keys.RETURN) sleep(1.5) driver.find_element_by_link_text("Latest").click() data = [] tweet_ids = set() last_position = driver.execute_script("return window.pageYOffset;") scrolling = True while scrolling: posts = driver.find_elements_by_xpath('//div[@data-testid="tweet"]') for post in posts[-15:]: tweet = scrap_tweets(post) if tweet: tweet_id = "".join(tweet) if tweet_id not in tweet_ids: tweet_ids.add(tweet_id) data.append(tweet) scroll_attempt = 0 while True: driver.execute_script( "window.scrollTo(0,document.body.scrollHeight);") sleep(1) curr_position = driver.execute_script("return window.pageYOffset;") if last_position == curr_position: scroll_attempt += 1 if scroll_attempt >= 3: scrolling = False break else: sleep(2) else: last_position = curr_position break return data
from msedge.selenium_tools import Edge, EdgeOptions from selenium.webdriver.common.keys import Keys import time import random options = EdgeOptions() options.use_chromium = True driver = Edge(options=options) driver.get("https://www.instagram.com/") driver.maximize_window() time.sleep(1) actions = driver.find_element_by_tag_name('body') actions.send_keys(Keys.TAB * 3, Keys.ENTER) inputElement = driver.find_element_by_xpath( "/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[1]/div/label/input" ) inputElement.send_keys("armaldoFransico", Keys.TAB, "criptografia", Keys.ENTER) time.sleep(5) actions = driver.find_element_by_xpath( '/html/body/div[1]/section/main/div/div/div/div/button') actions.click() time.sleep(3) actions = driver.find_element_by_tag_name('body') actions.send_keys(Keys.TAB * 2, Keys.ENTER) time.sleep(4) driver.execute_script("window.scrollTo(0, 300)") time.sleep(4)
def find_link_metadata (link): options = EdgeOptions() options.use_chromium = True options.add_argument("headless") driver = Edge(options = options) row_dict = {} row_dict['title'] = '' row_dict['Is_link_broken'] = 0 row_dict['Is_SQL_Server'] = 0 row_dict['Is_SQL_DB'] = 0 row_dict['Is_SQL_MI'] = 0 row_dict['Is_Synapse'] = 0 row_dict['Is_PDW'] = 0 row_dict['Is_Other'] = 0 row_dict['author'] = '' row_dict['updated_at'] = '2000-01-01 01:01 PM' row_dict['link']=link try: html = urlopen(link) except HTTPError as e: row_dict.update(Is_link_broken = 1) return row_dict except ValueError as v: print("invalid Link") return None except: return None driver.get(link) bs = BeautifulSoup(driver.page_source, 'html.parser') # print(bs.prettify()) # print('*' * 1000) row_dict = {} row_dict['title'] = '' row_dict['Is_link_broken'] = 0 row_dict['Is_SQL_Server'] = 0 row_dict['Is_SQL_DB'] = 0 row_dict['Is_SQL_MI'] = 0 row_dict['Is_Synapse'] = 0 row_dict['Is_PDW'] = 0 row_dict['Is_Other'] = 0 row_dict['author'] = '' row_dict['updated_at'] = '2000-01-01 01:01 PM' row_dict['link']=link try: html = urlopen(link) except HTTPError as e: row_dict.update(Is_link_broken = 1) return row_dict try: title= bs.find('title') row_dict.update(title = title.text) except AttributeError as e: row_dict.update(title = 'Unable To Find') try: tokens = bs.find_all('token') services = [] for token in tokens: services.append(token.text) for i in services: if i == 'SQL Server (all supported versions) ': row_dict.update(Is_SQL_Server = 1) elif i == 'Azure SQL Database': row_dict.update(Is_SQL_DB= 1) elif i == 'Azure SQL Managed Instance': row_dict.update(Is_SQL_MI = 1) elif i == 'Azure Synapse Analytics': row_dict.update(Is_Synapse = 1) elif i == 'Parallel Data Warehouse': row_dict.update(Is_PDW = 1) else: row_dict.update(Is_Other = 1) except AttributeError as e: row_dict.update(Is_SQL_Server = -1) row_dict.update(Is_SQL_DB= -1) row_dict.update(Is_SQL_MI = -1) row_dict.update(Is_Synapse = -1) row_dict.update(Is_PDW = -1) row_dict.update(Is_Other = -1) try: meta = bs.find_all('meta') for i in meta: if i.get('name') =='ms.author': row_dict.update(author=i.get('content')) if i.get('name') =='updated_at': row_dict.update(updated_at= i.get('content')) except AttributeError as e: row_dict.update(author='Unkown') row_dict.update(updated_at= '1900-01-01') return row_dict
from msedge.selenium_tools import Edge, EdgeOptions from selenium.webdriver.common.keys import Keys import time import random options = EdgeOptions() options.use_chromium = True word_list=["https://pt.wikipedia.org/wiki/Border_Gateway_Protocol", "https://pt.wikipedia.org/wiki/Multi_Protocol_Label_Switching", "https://pt.wikipedia.org/wiki/Open_Shortest_Path_First"] driver = Edge(options=options) driver.get("https://pt.wikipedia.org/") driver.maximize_window() time.sleep(5) driver.get(random.choice(word_list)) time.sleep(4) driver.execute_script("window.scrollTo(0, 300)") time.sleep(4) driver.execute_script("window.scrollTo(300, 600)") time.sleep(4) driver.execute_script("window.scrollTo(600, 900)") time.sleep(4) driver.execute_script("window.scrollTo(900, 1200)") time.sleep(4) driver.execute_script("window.scrollTo(1200, 1500)") time.sleep(4) driver.close()
def get_browser(_config_, path_prefix=""): """ 获取浏览器对象 :return: """ browser_type = _config_['selenium']['browserType'] headless = _config_['selenium']['headless'] binary = _config_['selenium']['binary'] user_agent = _config_['user-agent'][0] _browser_ = None try: if browser_type == 'Chrome': chrome_options = webdriver.ChromeOptions() # 防止在某些情况下报错` chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.add_experimental_option( "excludeSwitches", ['enable-automation', 'enable-logging']) chrome_options.add_argument(f'user-agent={user_agent}') if binary != "": # 当找不到浏览器时需要在 config 里配置路径 chrome_options.binary_location = binary if headless: chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') if sys.platform == 'linux': _browser_ = webdriver.Chrome( executable_path=get_file(path_prefix + "./drivers/chromedriver"), desired_capabilities={}, options=chrome_options) elif sys.platform == 'darwin': _browser_ = webdriver.Chrome( executable_path=get_file(path_prefix + "./drivers/chromedriver"), desired_capabilities={}, options=chrome_options) elif sys.platform == 'win32': _browser_ = webdriver.Chrome( executable_path=get_file(path_prefix + "./drivers/chromedriver"), desired_capabilities={}, options=chrome_options) _browser_.set_window_size(500, 700) elif browser_type == 'Edge': from msedge.selenium_tools import Edge, EdgeOptions edge_options = EdgeOptions() edge_options.use_chromium = True edge_options.add_argument('--no-sandbox') edge_options.add_argument('--disable-dev-shm-usage') edge_options.add_experimental_option( "excludeSwitches", ['enable-automation', 'enable-logging']) if binary != "": edge_options.binary_location = binary if headless: edge_options.add_argument('--headless') edge_options.add_argument('--disable-gpu') if sys.platform == 'linux': _browser_ = Edge( executable_path=get_file(path_prefix + "./drivers/msedgedriver"), options=edge_options, capabilities={}) elif sys.platform == 'darwin': _browser_ = Edge( executable_path=get_file(path_prefix + "./drivers/msedgedriver"), capabilities={}, options=edge_options) elif sys.platform == 'win32': _browser_ = Edge( executable_path=get_file(path_prefix + "./drivers/msedgedriver"), capabilities={}, options=edge_options) _browser_.set_window_size(500, 700) elif browser_type == 'Firefox': # 先清除上次的日志 if not os.path.exists(get_file("./logs")): os.mkdir(get_file("./logs/")) open(get_file("./logs/geckodriver.log"), "w").close() firefox_options = webdriver.FirefoxOptions() firefox_options.log.level = "fatal" if binary != "": firefox_options.binary_location = binary if headless: firefox_options.add_argument('--headless') firefox_options.add_argument('--disable-gpu') if sys.platform == 'linux': _browser_ = webdriver.Firefox( executable_path=get_file('./drivers/geckodriver'), options=firefox_options, service_log_path=get_file("./logs/geckodriver.log")) elif sys.platform == 'darwin': _browser_ = webdriver.Firefox( executable_path=get_file('./drivers/geckodriver'), options=firefox_options) elif sys.platform == 'win32': _browser_ = webdriver.Firefox( executable_path=get_file('./drivers/geckodriver'), options=firefox_options) _browser_.set_window_size(500, 700) else: raise WebDriverException return _browser_ except WebDriverException as e: # 驱动问题 if "This version of ChromeDriver only supports Chrome version" in e.args.__str__( ): print("\r[%s] [ERROR] 浏览器错误(chromedriver版本错误),请比对前三位版本号" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) elif "'chromedriver' executable needs to be in PATH" in e.args.__str__( ): print("\r[%s] [ERROR] 浏览器错误,请检查你下载并解压好的驱动是否放在drivers目录下" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) elif "unknown error: cannot find Chrome binary" in e.args.__str__(): print( "\r[%s] [ERROR] 浏览器错误(Chrome浏览器可执行文件路径未成功识别),请在配置文件中修改selenium.binary为浏览器可执行文件绝对路径" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) else: print( "\r[%s] [ERROR] 浏览器错误, 请检查你下载并解压好的驱动是否放在drivers目录下,如需帮助请及时反馈; err: %s" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), e.args.__str__())) sys.exit(1)
import xlsxwriter import bs4 from msedge.selenium_tools import Edge, EdgeOptions excel = xlsxwriter.Workbook("excel.xlsx") sheet = excel.add_worksheet() sheet.set_default_row(30) row = 0 col = 0 op = EdgeOptions() op.use_chromium = True driver = Edge(options=op) bold = excel.add_format({'bold': True}) sheet.write(row, col, "Sr.No", bold) sheet.write(row, col + 1, "Question", bold) sheet.write(row, col + 2, "Option A", bold) sheet.write(row, col + 3, "Option B", bold) sheet.write(row, col + 4, "Option C", bold) sheet.write(row, col + 5, "Option D", bold) sheet.write(row, col + 6, "Answer", bold) row += 1 for pageEnd in range(1, 10): driver.get( """https://ssconlineexam.com/general-science-mcq-questions-and-answers-for-competitive-exams&page=""" + str(pageEnd)) source = driver.page_source
class Sei: __area_inicial = None __windows_before = 0 __windows_after = 0 def __init__(self, headless=False, executable_path='chromedriver'): if 'chromedriver' in executable_path: chrome_options = Options() chrome_options.add_argument('--enable-javascript') chrome_options.add_argument('--window-size=1440,900') chrome_options.add_argument("--disable-extensions") chrome_options.add_argument("--proxy-server='direct://'") chrome_options.add_argument("--proxy-bypass-list=*") chrome_options.add_argument("--start-maximized") chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--ignore-certificate-errors') if headless: chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') self.driver = webdriver.Chrome(executable_path=executable_path, options=chrome_options) elif 'msedgedriver' in executable_path: edge_options = EdgeOptions() edge_options.use_chromium = True edge_options.add_argument('enable-javascript') edge_options.add_argument('window-size=1440,900') edge_options.add_argument("disable-extensions") edge_options.add_argument("proxy-server='direct://'") edge_options.add_argument("proxy-bypass-list=*") edge_options.add_argument("start-maximized") edge_options.add_argument('disable-dev-shm-usage') edge_options.add_argument('no-sandbox') edge_options.add_argument('ignore-certificate-errors') if headless: edge_options.add_argument('headless') edge_options.add_argument('disable-gpu') self.driver = Edge(executable_path=executable_path, options=edge_options) def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): self.close() def start_driver(self, url, usuario=None, senha=None): if usuario == None: usuario = input('Digite o usuário: ') if senha == None: senha = getpass('Digite a senha: ') self.driver.get(url) usuario_field = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "txtUsuario"))) senha_field = self.driver.find_element_by_id('pwdSenha') botao_acessar = self.driver.find_element_by_id('sbmLogin') usuario_field.clear() usuario_field.send_keys(usuario) senha_field.clear() senha_field.send_keys(senha) botao_acessar.click() alerta = self.fechar_alerta() if alerta: raise Exception(alerta) # usuário ou senha inválido self.__area_incial = self.get_area() def go_to(self, numero_sei): if self.__windows_after > self.__windows_before: self.driver.close() self.driver.switch_to.window( self.driver.window_handles[self.__windows_before - 1]) self.driver.switch_to.default_content() pesquisa = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "txtPesquisaRapida"))) pesquisa.clear() pesquisa.send_keys(str(numero_sei)) formPesquisaRapida = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located( (By.ID, "frmProtocoloPesquisaRapida"))) self.__windows_before = len(self.driver.window_handles) formPesquisaRapida.submit() self.__windows_after = len(self.driver.window_handles) if self.__windows_after > self.__windows_before: self.driver.switch_to.window( self.driver.window_handles[self.__windows_after - 1]) def is_processo_aberto(self, area=None, processo=None): if processo: self.go_to(processo) else: self.driver.switch_to.default_content() try: ifrVisualizacao = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrVisualizacao"))) self.driver.switch_to.frame(ifrVisualizacao) informacao = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "divInformacao"))) mensagem = informacao.text aberto = 'aberto' in mensagem if area: regex = '(?im)^(.*)(' + area + ')[^0-9a-z](.*)$' matches = search(regex, mensagem) if matches: aberto = True else: aberto = False self.driver.switch_to.default_content() except: aberto = None mensagem = 'Impossível abrir mensagem do processo' return aberto, mensagem def get_processo_anexador(self, processo=None): if processo: self.go_to(processo) else: self.driver.switch_to.default_content() ifrVisualizacao = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrVisualizacao"))) self.driver.switch_to.frame(ifrVisualizacao) informacao = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "divInformacao"))) procAnex = None if 'Processo anexado ao processo' in informacao.text: processoAnexador = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located( (By.XPATH, "//*[@id=\"divInformacao\"]/div/a"))) procAnex = processoAnexador.text self.driver.switch_to.default_content() return procAnex def get_area(self): self.driver.switch_to.default_content() select = Select(self.driver.find_element_by_id('selInfraUnidades')) return select.all_selected_options[0].text def seleciona_area(self, area): self.driver.switch_to.default_content() select = Select(self.driver.find_element_by_id('selInfraUnidades')) all_selected_options = select.all_selected_options for option in all_selected_options: if area == option.text: return True select = Select(self.driver.find_element_by_id('selInfraUnidades')) options = select.options for option in options: if area == option.text: select.select_by_visible_text(area) Select( WebDriverWait(self.driver, 3).until( EC.presence_of_element_located( (By.ID, 'selInfraUnidades')))) return True return False def clicar_botao(self, botao): self.driver.switch_to.default_content() ifrVisualizacao = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrVisualizacao"))) self.driver.switch_to.frame(ifrVisualizacao) arvore = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "divArvoreAcoes"))) botoes = arvore.find_elements(By.XPATH, '//*[@id=\"divArvoreAcoes\"]/a') for b in botoes: img = b.find_element(By.XPATH, 'img') if botao in img.get_attribute('title'): b.click() try: WebDriverWait(self.driver, 1).until( EC.alert_is_present(), 'Timed out waiting for PA creation ' + 'confirmation popup to appear.') except: try: self.driver.switch_to.default_content() except: None return True return False def fechar_alerta(self): alerta = None try: WebDriverWait(self.driver, 3).until( EC.alert_is_present(), 'Timed out waiting for PA creation ' + 'confirmation popup to appear.') alert = self.driver.switch_to.alert alerta = alert.text alert.accept() self.driver.switch_to.default_content() except TimeoutException: None return alerta def is_sobrestado(self, area=None, processo=None): if processo: self.go_to(processo) else: self.driver.switch_to.default_content() ifrVisualizacao = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrVisualizacao"))) self.driver.switch_to.frame(ifrVisualizacao) informacao = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "divInformacao"))) sobrestado = 'sobrestado' in informacao.text mensagem = informacao.text self.driver.switch_to.default_content() if area: regex = '(?im)^(.*)(' + area + ')[^0-9a-z](.*)$' matches = search(regex, informacao.text) return sobrestado, matches != None else: return sobrestado, mensagem def sobrestar_processo(self, motivo, processo=None): if processo: self.go_to(processo) else: self.driver.switch_to.default_content() if self.clicar_botao('Sobrestar Processo'): ifrVisualizacao = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrVisualizacao"))) self.driver.switch_to.frame(ifrVisualizacao) self.driver.find_element(By.ID, 'divOptSomenteSobrestar').click() motivoField = self.driver.find_element(By.ID, 'txaMotivo') motivoField.clear() motivoField.send_keys(motivo) self.driver.find_element(By.ID, 'sbmSalvar').click() self.driver.switch_to.default_content() return True return False def remover_sobrestamento(self, processo=None): if processo: self.go_to(processo) if self.clicar_botao('Remover Sobrestamento do Processo'): self.fechar_alerta() return True return False def publicar(self, resumo_ementa, data_disponibilizacao, documento=None, dou=False, secao=None, pagina=None): if documento: self.go_to(documento) else: self.driver.switch_to.default_content() if self.clicar_botao('Agendar Publicação'): ifrVisualizacao = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrVisualizacao"))) self.driver.switch_to.frame(ifrVisualizacao) resumo_ementa_text_field = self.driver.find_element( By.ID, 'txaResumo') resumo_ementa_text_field.clear() resumo_ementa_text_field.send_keys(resumo_ementa) disponibilizacao = self.driver.find_element( By.ID, 'txtDisponibilizacao') disponibilizacao.clear() disponibilizacao.send_keys(data_disponibilizacao) if dou: select = Select(self.driver.find_element_by_id('selVeiculoIO')) select.select_by_visible_text('DOU') select = Select( WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "selSecaoIO")))) WebDriverWait(self.driver, 3).until( EC.presence_of_element_located( (By.CSS_SELECTOR, "option[value='" + secao if secao else '3' + "']"))) select.select_by_visible_text(secao if secao else '3') pagina_text_field = self.driver.find_element( By.ID, 'txtPaginaIO') pagina_text_field.clear() pagina_text_field.send_keys(pagina if pagina else '') disponibilizacao = self.driver.find_element(By.ID, 'txtDataIO') disponibilizacao.clear() disponibilizacao.send_keys(data_disponibilizacao) self.driver.find_element_by_id('btnSalvar').click() self.driver.switch_to.default_content() return True return False def get_conteudo_documento(self, documento=None): if documento: self.go_to(documento) else: self.driver.switch_to.default_content() try: ifrVisualizacao = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrVisualizacao"))) self.driver.switch_to.frame(ifrVisualizacao) ifrArvoreHtml = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrArvoreHtml"))) self.driver.switch_to.frame(ifrArvoreHtml) documento_conteudo = self.driver.find_element_by_xpath( '/html/body').get_attribute('innerHTML') documento_conteudo = sub( r'\\n', '', documento_conteudo) # retirar quebra de páginas documento_conteudo = sub(r'\s\s+?', ' ', documento_conteudo) # tira espaços duplos documento_conteudo = sub(r' ', ' ', documento_conteudo) # tira espaços duplos documento_conteudo = documento_conteudo.strip( ) # retirar quebras de páginas que tenham restado return documento_conteudo except: raise Exception('Conteúdo do documento %s não encontrado.' % documento) finally: self.driver.switch_to.default_content() def get_documento_element_by_id(self, id, documento=None): if documento: self.go_to(documento) else: self.driver.switch_to.default_content() try: if (self.__windows_after == self.__windows_before): ifrVisualizacao = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrVisualizacao"))) self.driver.switch_to.frame(ifrVisualizacao) ifrArvoreHtml = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrArvoreHtml"))) self.driver.switch_to.frame(ifrArvoreHtml) return self.driver.find_element_by_id(id).text except: raise Exception('Conteúdo do documento %s não encontrado.' % documento) finally: self.driver.switch_to.default_content() def get_documento_elements_by_id(self, id, documento=None): if documento: self.go_to(documento) else: self.driver.switch_to.default_content() try: if (self.__windows_after == self.__windows_before): ifrVisualizacao = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrVisualizacao"))) self.driver.switch_to.frame(ifrVisualizacao) ifrArvoreHtml = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrArvoreHtml"))) self.driver.switch_to.frame(ifrArvoreHtml) elements = self.driver.find_elements_by_id(id) return [element.text for element in elements] except: raise Exception('Conteúdo do documento %s não encontrado.' % documento) finally: self.driver.switch_to.default_content() def get_documento_element_by_xpath(self, xpath, documento=None): if documento: self.go_to(documento) else: self.driver.switch_to.default_content() try: if (self.__windows_after == self.__windows_before): ifrVisualizacao = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrVisualizacao"))) self.driver.switch_to.frame(ifrVisualizacao) ifrArvoreHtml = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrArvoreHtml"))) self.driver.switch_to.frame(ifrArvoreHtml) return self.driver.find_element_by_xpath(xpath).text except: raise Exception('Conteúdo do documento %s não encontrado.' % documento) finally: self.driver.switch_to.default_content() def get_documento_elements_by_xpath(self, xpath, documento=None): if documento: self.go_to(documento) else: self.driver.switch_to.default_content() try: if (self.__windows_after == self.__windows_before): ifrVisualizacao = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrVisualizacao"))) self.driver.switch_to.frame(ifrVisualizacao) ifrArvoreHtml = WebDriverWait(self.driver, 3).until( EC.presence_of_element_located((By.ID, "ifrArvoreHtml"))) self.driver.switch_to.frame(ifrArvoreHtml) elements = self.driver.find_elements_by_xpath(xpath) return [element.text for element in elements] except: raise Exception('Conteúdo do documento %s não encontrado.' % documento) finally: self.driver.switch_to.default_content() def close(self, voltar=True): if voltar: self.seleciona_area(self.__area_incial) self.driver.close() self.driver.quit()
from msedge.selenium_tools import Edge, EdgeOptions options = EdgeOptions() options.use_chromium = True options.headless = True options.page_load_strategy = 'eager' options.add_argument('log-level=3') # Set the threshold for selenium to WARNING from selenium.webdriver.remote.remote_connection import LOGGER as seleniumLogger seleniumLogger.setLevel(logging.WARNING) # Set the threshold for urllib3 to WARNING from urllib3.connectionpool import log as urllibLogger urllibLogger.setLevel(logging.WARNING) driver = Edge(options=options) reload_count = 0 print("Done!") # Twilio Setup if TWILIO_TO_NUM and TWILIO_FROM_NUM and TWILIO_SID and TWILIO_AUTH: USE_TWILIO = True print("Enabling Twilio... ", end='') from twilio.rest import Client client = Client(TWILIO_SID, TWILIO_AUTH) print("Done!") # Discord Setup if DISCORD_WEBHOOK_URL: USE_DISCORD_HOOK = True
break else: ticket = 99 if not lista: print("no hay numeros") else: if ticket == 99: print("no hay numero de 7 digitos") else: print("el ticket debe ser", ticket) print(lista) ticket = lista[0] print(ticket) edge_option = EdgeOptions() edge_option.add_argument("hide_console") driver = Edge("C:\Google\msedgedriver", service_args=["hide_console"]) url = "http://10.1.27.11:8080/tfs/TFSYPF/E2E/_workitems?_a=edit&id=" urlarmada = url + ticket driver.get(urlarmada) driver.implicitly_wait(8) attachment = "ui-id-7" driver.find_element_by_id(attachment).click() direarchivo = dir_inicial + nombre_archivo driver.implicitly_wait(5) driver.find_element_by_xpath( "/html/body/div[4]/div[2]/div/form/input[1]").send_keys( direarchivo) driver.implicitly_wait(5)
def main(): args = sys.argv f = open(args[4], "r") Lines = f.readlines() names, profession, nationality, job = [], [], [], [] for line in Lines: array = line.split(",") names.append(array[0]) profession.append(array[1]) nationality.append(array[2]) job.append(array[3].replace("\n", "")) for name in names: print("Query:", name, ".\nProcessing...") user = '******' search_term = f'{name} filter:verified' options = EdgeOptions() options.use_chromium = True driver = Edge(options=options) driver.get('https://www.twitter.com/login') driver.maximize_window() sleep(2) username = driver.find_element_by_xpath( '//input[@name="session[username_or_email]"]') username.send_keys(user) password = driver.find_element_by_xpath( '//input[@name="session[password]"]') password.send_keys('donkey123') password.send_keys(Keys.RETURN) sleep(1) search_input = driver.find_element_by_xpath( '//input[@aria-label="Search query"]') search_input.send_keys(search_term) search_input.send_keys(Keys.RETURN) sleep(1) driver.find_element_by_link_text('People').click() sleep(3) driver.find_element_by_xpath( '//div[@class="css-1dbjc4n r-j7yic r-qklmqi r-1adg3ll r-1ny4l3l"]' ).click() sleep(3) data = [] tweet_data = [] start = 0 end = 500 for i in range(0, 5): sleep(1) cards = driver.find_elements_by_xpath( '//div[@data-testid="tweet"]') card = cards[i] tweet = get_tweet_data(card) for card in cards: data = get_tweet_data(card) if data: tweet_data.append(data) driver.execute_script(f'window.scrollTo({start},{end});') start += 500 end += 500 driver.close() tweets = set(tweet_data) write_to_csv(name, tweets) df = pd.read_csv(f'{name}.csv') Twitter_sentiment = Twitter_sentiment_model(df) Twitter_toxic = Twitter_toxic_model(df) Big5 = Big5_model(df) create_report(name, tweets, Twitter_sentiment, Twitter_toxic, Big5)
def get_browser(_config): """ 获取浏览器对象 :return: """ browser_type = _config['browserType'] headless = _config['headless'] binary = _config['binary'] try: if browser_type == 'Chrome': chrome_options = webdriver.ChromeOptions() # 防止在某些情况下报错` chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.add_experimental_option("excludeSwitches", ['enable-automation', 'enable-logging']) if binary != "": # 当找不到浏览器时需要在 config 里配置路径 chrome_options.binary_location = binary if headless: chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') if sys.platform == 'linux': _browser = webdriver.Chrome(executable_path=get_file("./drivers/chromedriver"), desired_capabilities={}, options=chrome_options) elif sys.platform == 'darwin': _browser = webdriver.Chrome(executable_path=get_file("./drivers/chromedriver"), desired_capabilities={}, options=chrome_options) elif sys.platform == 'win32': _browser = webdriver.Chrome(executable_path=get_file("./drivers/chromedriver"), desired_capabilities={}, options=chrome_options) elif browser_type == 'Edge': from msedge.selenium_tools import Edge, EdgeOptions edge_options = EdgeOptions() edge_options.use_chromium = True edge_options.add_argument('--no-sandbox') edge_options.add_argument('--disable-dev-shm-usage') edge_options.add_experimental_option("excludeSwitches", ['enable-automation', 'enable-logging']) if binary != "": edge_options.binary_location = binary if headless: edge_options.add_argument('--headless') edge_options.add_argument('--disable-gpu') if sys.platform == 'linux': _browser = Edge(executable_path=get_file("./drivers/msedgedriver"), options=edge_options, capabilities={}) elif sys.platform == 'darwin': _browser = Edge(executable_path=get_file("./drivers/msedgedriver"), capabilities={}, options=edge_options) elif sys.platform == 'win32': _browser = Edge(executable_path=get_file("./drivers/msedgedriver"), capabilities={}, options=edge_options) elif browser_type == 'Firefox': # 先清除上次的日志 if not os.path.exists(get_file("./logs")): os.mkdir(get_file("./logs/")) open(get_file("./logs/geckodriver.log"), "w").close() firefox_options = webdriver.FirefoxOptions() firefox_options.log.level = "fatal" if binary != "": firefox_options.binary_location = binary if headless: firefox_options.add_argument('--headless') firefox_options.add_argument('--disable-gpu') if sys.platform == 'linux': _browser = webdriver.Firefox(executable_path=get_file('./drivers/geckodriver'), options=firefox_options, service_log_path=get_file("./logs/geckodriver.log")) elif sys.platform == 'darwin': _browser = webdriver.Firefox(executable_path=get_file('./drivers/geckodriver'), options=firefox_options) elif sys.platform == 'win32': _browser = webdriver.Firefox(executable_path=get_file('./drivers/geckodriver'), options=firefox_options) else: raise WebDriverException return _browser except WebDriverException: # 驱动问题 print_log("ERROR", "浏览器错误", "请检查你的驱动和配置")
def create_webdriver() -> Edge: options = EdgeOptions() options.use_chromium = True options.headless = True driver = Edge(options=options) return driver
def Restart_Modem(): options = EdgeOptions() options.use_chromium = True options.add_argument("-inprivate") edge_browser = Edge(options=options) edge_browser.get('http://192.168.0.1') time.sleep(2) print('Welcome') try: login = edge_browser.find_element_by_name('username') password = edge_browser.find_element_by_name('password') sign = edge_browser.find_element_by_class_name('styled_button_s') login.clear() password.clear() login.send_keys('admin') password.send_keys('admin') time.sleep(2) sign.click() print('Sign in') alert = Alert(edge_browser) time.sleep(2) edge_browser.get('http://192.168.0.1/saveconf.htm') time.sleep(2) system = edge_browser.find_element_by_id('three_level_menu1') system.click() time.sleep(2) reboot = edge_browser.find_element_by_name('reboot') reboot.click() alert.accept() time.sleep(70) print('Reboot') edge_browser.quit() except: print('Problem with restarting modem') edge_browser.quit()
def chinahpo(hpo_queue): while hpo_queue.empty() is not True: hpo = hpo_queue.get() # 如果使用IP池,则不进行随机等待 s = random.randint(5, 10) print(hpo, "等待 " + str(s) + "秒") time.sleep(s) ip = randomIP() # ip = "socks5://127.0.0.1:1080" hpo_ip = hpo + "\t" + ip print(hpo_ip) options = EdgeOptions() options.use_chromium = True options.add_argument("headless") # options.add_argument("disable-gpu") options.add_argument("--proxy-server=http://{ip}".format(ip=ip)) options.add_argument("--disable-blink-features") options.add_argument("--disable-blink-features=AutomationControlled") options.add_argument("start-maximized") options.add_experimental_option("excludeSwitches", ["enable-automation"]) options.add_experimental_option("useAutomationExtension", False) geo = get_timezone_geolocation(ip) print(geo) geo_json = {"latitude": geo[1], "longitude": geo[2], "accuracy": 1} timezone = {"timezoneId": geo[0]} preferences = { "webrtc.ip_handling_policy": "disable_non_proxied_udp", "webrtc.multiple_routes_enabled": False, "webrtc.nonproxied_udp_enabled": False } options.add_experimental_option("prefs", preferences) msedge = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedgedriver.exe" driver = Edge(options=options, executable_path=msedge) script = "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})" driver.execute_script(script) UA = UserAgent().random # UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.53 Safari/537.36" driver.execute_cdp_cmd("Network.setUserAgentOverride", {"userAgent": UA}) driver.execute_cdp_cmd("Emulation.setGeolocationOverride", geo_json) driver.execute_cdp_cmd("Emulation.setTimezoneOverride", timezone) print(driver.execute_script("return navigator.userAgent;")) hpid = hpo.split(":")[1] url = "http://www.chinahpo.org/#/searchList?trigger=1&tabType=1&searchContent=HP%3A{hpid}".format( hpid=hpid) try: driver.get(url) strtemp = url print("网址:", strtemp) except Exception: print("get page error", hpo) time.sleep(2) with open("html2/hp_" + hpid + ".html", "a+", encoding="utf-8") as f: f.write(str(driver.page_source)) driver.close() fin = open("finish.txt", "a") fin.write(hpo + "\n") fin.close() size = getDocSize("html2/hp_" + hpid + ".html") if 9000 <= size <= 15000: checkIP = open("ip_check_better.txt", "a") checkIP.write(hpo_ip + "\n") checkIP.close()
from msedge.selenium_tools import options from msedge.selenium_tools import Edge, EdgeOptions from time import sleep options = EdgeOptions() options.use_chromium = True driver = Edge(options=options) options.add_experimental_option("excludeSwitches", ['enable-automation']) kodSekolah = "NEB2054" driver.get( "https://docs.google.com/forms/d/e/1FAIpQLSduotkz5L48QN_vXksFCerIfHF4ihDQyxlARbL4BneSeqzNWg/viewform" ) print("Google sites opened") sleep(0.5) KodSekolah_box = driver.find_element_by_class_name( "quantumWizTextinputPaperinputEl") KodSekolah_box.send_keys(kodSekolah) sleep(0.2)
import time import io from msedge.selenium_tools import Edge, EdgeOptions from selenium.webdriver.common.keys import Keys # Launch Microsoft Edge (EdgeHTML) if __name__ == '__main__': tract_id = '38077970700' address_id = '' driver = Edge( executable_path= r"C:\Users\faris\documents\akeb\opportunity-atlas\atlascrape\msedgedriver.exe" ) # driver = Edge(executable_path="./msedgedriver.exe") # Launch Microsoft Edge (Chromium) options = EdgeOptions() options.use_chromium = True driver = Edge(options=options) print("Getting atlas") # get opportunity atlas driver.get("https://opportunityatlas.org/") time.sleep(10) # click on get started atlas get_started = driver.find_element_by_xpath( "/html/body/div[3]/div[2]/div[1]/p[5]/button") get_started.click()
def start(self) -> WebDriver: return Edge(executable_path=EdgeChromiumDriverManager().install(), capabilities=self._set_capabilities_(), options=self._set_options_())
from msedge.selenium_tools import Edge, EdgeOptions import random import time # Launch Microsoft Edge (Chromium) options = EdgeOptions() options.use_chromium = True driver = Edge(r"C:\Users\Sid\Downloads\msedgedriver", options=options) driver.maximize_window() year = "2017" #2017, 2018, 2019 or 2020 url = f"https://www.nirfindia.org/{year}/OverallRanking.html" driver.get(url) all_elems = driver.find_elements_by_tag_name("a") stringlist = [] for elem in all_elems: txt = elem.get_attribute("href") if type(txt) == str: if txt.endswith(".pdf"): stringlist.append(txt) print(stringlist) ##CHANGE all_elems = driver.find_elements_by_tag_name("td")
def main(): searchtext = input() num_requested = int(input()) number_of_scrolls = num_requested / 400 + 1 # number_of_scrolls * 400 images will be opened in the browser if not os.path.exists(download_path + searchtext.replace(" ", "_")): os.makedirs(download_path + searchtext.replace(" ", "_")) url = "https://www.google.co.in/search?q="+searchtext+"&source=lnms&tbm=isch" chrome_driver_path = "msedgedriver.exe" browser_path = "C:\\Program Files (x86)\\Microsoft\\Edge Beta\\Application\\msedge.exe" option = EdgeOptions() option.binary_location = browser_path driver = Edge(executable_path = chrome_driver_path, options = option) driver.get(url) headers = {} headers['User-Agent'] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36" extensions = {"jpg", "jpeg", "png", "gif"} img_count = 0 downloaded_img_count = 0 for _ in range(int(number_of_scrolls)): for __ in range(15): driver.execute_script("window.scrollBy(0, 1000000)") time.sleep(0.2) time.sleep(0.5) try: driver.find_element_by_xpath( "//input[@value='Show more results']").click() except Exception as e: print("Less images found: {}".format(e)) break html = driver.page_source.split('"') imges = [] links = [] for i in html: if i.startswith('https:') and ('gstatic' not in i) and ('google' not in i): links.append(i.split('"')[0]) for i in html: if i.startswith('http') and 'usqp=CAU' in i.split('.')[-1]: imges.append(i.split('"')[0]) for i in html: if i.startswith('http') and i.split('"')[0].split('.')[-1] in extensions: imges.append(i.split('"')[0]) links = list(set(links)) imges = list(set(imges)) print(imges) links_left = Diff(links, imges) #removing duplicates urls_new = [] [urls_new.append(x) for x in links_left if x not in urls_new] file1 = open("page_source.txt", "w", encoding='utf8') file1.writelines(urls_new) img_type = [] print("Total images: {}\n".format(len(imges))) for img in imges: img_count += 1 print("Downloading image {}:{}".format(img_count, img)) img_type = img.rsplit('.', 1) try: req = Request(img, headers=headers) raw_img = urlopen(req).read() f = open(download_path+searchtext.replace(" ", "_")+"/" + str(downloaded_img_count)+"."+"jpeg", "wb") f.write(raw_img) f.close downloaded_img_count += 1 except Exception as e: print("Download failed: {}".format(e)) finally: print if downloaded_img_count >= num_requested: break print("Total downloaded: {}/{}".format(downloaded_img_count, img_count)) print("Total images: {}\n".format(len(urls_new))) for url in urls_new: img_count = img_scp.img_download(url, download_path+searchtext.replace(" ", "_")+"/", img_count) driver.quit()
from selenium import webdriver from selenium.webdriver.common.keys import Keys 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.common.exceptions import NoSuchElementException from msedge.selenium_tools import Edge, EdgeOptions import time, pyautogui as pya, keyboard, random webdriver_location="msedgedriver.exe" options=EdgeOptions() options.use_chromium=True options.binary_location=r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe' browser=Edge(options=options,executable_path=webdriver_location) running=False keybind=input("\n\n\n[!!] -Start typeing keybind, press on start of test: ") while True: try: if keyboard.is_pressed(keybind) == True and running == False: browser.get("https://www.typing.com/student/typing-test/1-minute") runningEFE=True newtype="" typestring=[] print('-Reading...') elements=browser.find_elements_by_class_name('screenBasic-letter') print("-Typing...") for e in elements: text=e.get_attribute("textContent") print(text)
from datetime import datetime from urllib.request import urlopen, Request from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer WARNING = '\033[93m' WHITE = '\033[0m' OKCYAN = '\033[96m' OKGREEN = '\033[92m' options = EdgeOptions() options.use_chromium = True # Sin abrirnavegador options.headless = True options.add_argument('disable-gpu') options.add_argument('no-sandbox') driver = Edge(options=options, executable_path='msedgedriver.exe') vars = {} USERNAME = '******' PASSWORD = '******' EMAIL = '*****@*****.**' def wait_for_window(timeout=2): time.sleep(round(timeout / 1000)) wh_now = driver.window_handles wh_then = vars["window_handles"] if len(wh_now) > len(wh_then): return set(wh_now).difference(set(wh_then)).pop()
comentarios_num = card.find_element_by_xpath( './/div[@data-testid="reply"]').text retweets_num = card.find_element_by_xpath( './/div[@data-testid="retweet"]').text curtidas_num = card.find_element_by_xpath( './/div[@data-testid="like"]').text tweet = (apelido, username, data_postagem, respondendo, comentario, link_img, comentarios_num, retweets_num, curtidas_num) return tweet options = EdgeOptions() options.use_chromium = True options.headless = True driver = Edge(options=options) driver.get('https://twitter.com/search?q=vacina&src=typed_query') driver.find_element_by_link_text('Mais recentes').click() data = [] tweet_ids = set() last_position = driver.execute_script("return window.pageYOffset;") scrolling = True scroll_attempt = 0 i = 0 while scrolling: page_cards = driver.find_elements_by_xpath('//div[@data-testid="tweet"]') for card in page_cards[-15:]: tweet = get_tweet_data(card)
def launch(self, desired_capabilities=None, options=None): from selenium.webdriver import DesiredCapabilities self._set_config() if self._automation_browser == CHROME and self._automation_local: self.setup_chromedriver() chrome_capabilities = DesiredCapabilities.CHROME.copy() if options is not None: chrome_capabilities.update(options.to_capabilities()) if desired_capabilities is not None: chrome_capabilities.update(desired_capabilities) else: if desired_capabilities is not None: chrome_capabilities.update(desired_capabilities) return webdriver.Chrome(desired_capabilities=chrome_capabilities) if self._automation_browser == GECKO and self._automation_local: self.setup_geckodriver() firefox_capabilities = DesiredCapabilities.FIREFOX.copy() if options is not None: firefox_capabilities.update(options.to_capabilities()) if desired_capabilities is not None: firefox_capabilities.update(desired_capabilities) else: if desired_capabilities is not None: firefox_capabilities.update(desired_capabilities) return webdriver.Firefox(desired_capabilities=firefox_capabilities, service_log_path=os.path.join(ROOT_DIR, LOG_DIR, f'{GECKODRIVER}{LOG}')) if self._automation_browser == EDGE: self.setup_edgedriver() from msedge.selenium_tools import Edge, EdgeOptions edge_capabilities = DesiredCapabilities.EDGE.copy() if options is not None: edge_capabilities.update(options.to_capabilities()) if desired_capabilities is not None: edge_capabilities.update(desired_capabilities) else: if desired_capabilities is not None: edge_capabilities.update(desired_capabilities) from msedge.selenium_tools import Edge, EdgeOptions edge_options = EdgeOptions() edge_options.use_chromium = True edge_options.set_capability('platform', 'MAC' if OS_NAME == 'MAC' else 'WINDOWS') edge_capabilities.update(edge_options.to_capabilities()) return Edge(desired_capabilities=edge_options.to_capabilities()) if self._automation_browser == IE: if OS_NAME == 'MAC': raise NotImplementedError('Cannot launch IE browser on Mac.') self.setup_iedriver() ie_capabilities = DesiredCapabilities.INTERNETEXPLORER.copy() if options is not None: ie_capabilities.update(options.to_capabilities()) if desired_capabilities is not None: ie_capabilities.update(desired_capabilities) else: if desired_capabilities is not None: ie_capabilities.update(desired_capabilities) from selenium.webdriver import IeOptions ie_options = IeOptions() ie_options.ignore_protected_mode_settings = True ie_options.ensure_clean_session = True ie_options.require_window_focus = True ie_options.ignore_zoom_level = True ie_capabilities.update(ie_options.to_capabilities()) return webdriver.Ie(desired_capabilities=ie_capabilities) if self._automation_browser == SAFARI: if OS_NAME == 'WIN': raise NotImplementedError('Cannot launch safari browser on Windows.') return webdriver.Safari(desired_capabilities=desired_capabilities) remote_capabilities = DesiredCapabilities.CHROME.copy() if self._automation_browser == CHROME \ else DesiredCapabilities.FIREFOX.copy() if options is not None: remote_capabilities.update(options.to_capabilities()) if desired_capabilities is not None: remote_capabilities.update(desired_capabilities) else: if desired_capabilities is not None: remote_capabilities.update(desired_capabilities) return webdriver.Remote(command_executor=self._automation_url, desired_capabilities=remote_capabilities)
def create_driver(browser_name): if browser_name not in GlobalUtils.BROWSER_NAMES: raise Exception("Unsupported browser string: '%s' Use: %s" % (browser_name, GlobalUtils.BROWSER_NAMES)) spinner_locator_file = os.path.join(os.getcwd(), GlobalUtils.PROJECT_SPINNER_LOCATORS_FILE) if not os.path.isfile(spinner_locator_file): shutil.copyfile(GlobalUtils.FRAMEWORK_SPINNER_LOCATORS_FILE, spinner_locator_file) if __REMOTE_SERVER_ADDRESS: if _REMOTE_SERVER_CAPTIONS: desired_capabilities = _REMOTE_SERVER_CAPTIONS else: desired_capabilities = __get_desired_capabilities(browser_name) print(__REMOTE_SERVER_ADDRESS) print(desired_capabilities) _driver = webdriver.Remote(__REMOTE_SERVER_ADDRESS, desired_capabilities) return _driver if browser_name == GlobalUtils.BROWSER_NAMES[Browsers.IE]: # Read browser language from config import winreg try: my_lang = get_config_value("browser_language") country_key = get_country_key(my_lang) try: key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\International", 0, winreg.KEY_ALL_ACCESS) winreg.SetValueEx(key, "AcceptLanguage", 0, winreg.REG_SZ, str(country_key + ";q=0.5")) winreg.CloseKey(key) except Exception as e: try: winreg.CloseKey(key) throw_error("\nCould not set language value: " + str(e)) except Exception as msg: print(str(msg)) except: pass # Turn protected mode on for all zones try: for i in range(1, 5): key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\" + str(i), 0, winreg.KEY_ALL_ACCESS) try: _protected_values[i - 1] = winreg.QueryValueEx(key, "2500")[0] except WindowsError as e: pass winreg.SetValueEx(key, "2500", 0, winreg.REG_DWORD, 0) winreg.CloseKey(key) except Exception as e: try: winreg.CloseKey(key) reset_protected_mode() throw_error("\nCould not change Internet Explorer zone settings: " + str(e)) except Exception as msg: print(str(msg)) pass capabilities = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.IE]], "capabilities") ie_capabilities = DesiredCapabilities.INTERNETEXPLORER for arg in capabilities: ie_capabilities[arg["option"]] = eval(arg["text"]) # Adding driver to path if not GlobalUtils.is_linux(): print("Using IEDriverServer") if not os.path.join(GlobalUtils.RESOURCES_IE_PATH) in os.environ["PATH"]: print("Adding IEDriverServer to path") os.environ["PATH"] += os.pathsep + os.path.join(GlobalUtils.RESOURCES_IE_PATH) else: raise Exception("Linux can't use IEDriverServer") _driver = webdriver.Ie(capabilities=ie_capabilities) return _driver elif browser_name == GlobalUtils.BROWSER_NAMES[Browsers.CHROME]: options = webdriver.ChromeOptions() # enable chrome switches try: opt_values = get_config_value("browser_options") for opt_value in opt_values: options.add_argument("--" + opt_value) except: pass extension_if_cases = [] argument_if_cases = [] # enable cache cleaner for resource timings if get_config_value("enable_live_monitoring").lower() == 'true': extension_if_cases.append("enable_live_monitoring") # enable precise memory info if get_config_value("enable_precise_memory").lower() == 'true': argument_if_cases.append("enable_precise_memory") # Get add_argument options from xml add_arguments = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.CHROME]], "add_argument", argument_if_cases) # Get add_extensions options from xml add_extensions = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.CHROME]], "add_extension", extension_if_cases) # Get add_experimental_options options from xml add_experimental_options = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.CHROME]], "add_experimental_option") # add_argument using dict parsed from xml for arg in add_arguments: options.add_argument(eval(arg["text"])) # add_extension using dict parsed from xml for arg in add_extensions: options.add_extension(eval(arg["text"])) # add_experimental_option using dict parsed from xml for arg in add_experimental_options: try: # Selenium 2.26 options.add_experimental_option(arg["option"], eval(arg["text"])) except: pass # Adding driver to path if not GlobalUtils.is_linux(): print("Using 32bit win chromedriver") if not os.path.join(GlobalUtils.RESOURCES_CHROME32_PATH) in os.environ["PATH"]: print("Adding 32bit win chromedriver to path") os.environ["PATH"] += os.pathsep + os.path.join(GlobalUtils.RESOURCES_CHROME32_PATH) else: print("Using 64bit linux chromedriver") if not os.path.join(GlobalUtils.RESOURCES_LINUX_CHROME64_PATH) in os.environ["PATH"]: print("Adding 64bit linux chromedriver to path") os.environ["PATH"] += os.pathsep + os.path.join(GlobalUtils.RESOURCES_LINUX_CHROME64_PATH) _driver = webdriver.Chrome(chrome_options=options) try: selenium_library = BuiltIn().get_library_instance("SeleniumLibrary") selenium_library.register_driver(_driver, "default_gc") except: pass return _driver elif browser_name == GlobalUtils.BROWSER_NAMES[Browsers.FIREFOX]: profile = webdriver.FirefoxProfile() preference_if_cases = [] set_preferences = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.FIREFOX]], "set_preference", preference_if_cases) for arg in set_preferences: profile.set_preference(arg["option"], eval(arg["text"])) set_capabilities = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.FIREFOX]], "set_capabilities") firefox_capabilities = DesiredCapabilities.FIREFOX for arg in set_capabilities: firefox_capabilities[arg["option"]] = eval(arg["text"]) # Adding driver to path if not GlobalUtils.is_linux(): print("Using 32bit win geckodriver") # first we try to use 32bit wersion if not os.path.join(GlobalUtils.RESOURCES_GECKO32_PATH) in os.environ["PATH"]: print("Adding 32bit win geckodriver to path") os.environ["PATH"] += os.pathsep + os.path.join(GlobalUtils.RESOURCES_GECKO32_PATH) else: print("Using 64bit linux geckodriver") if not os.path.join(GlobalUtils.RESOURCES_LINUX_GECKO64_PATH) in os.environ["PATH"]: print("Adding 64bit linux geckodriver to path") os.environ["PATH"] += os.pathsep + os.path.join(GlobalUtils.RESOURCES_LINUX_GECKO64_PATH) try: _driver = webdriver.Firefox(firefox_profile=profile, capabilities=firefox_capabilities, log_path=_geckodriver_log_path) except WebDriverException as e: # try with 64bit version if we are using windows if not GlobalUtils.is_linux(): if os.path.join(GlobalUtils.RESOURCES_GECKO32_PATH) in os.environ["PATH"]: os.environ["PATH"] = os.environ["PATH"].replace(os.pathsep + os.path.join(GlobalUtils.RESOURCES_GECKO32_PATH), "") if not os.path.join(GlobalUtils.RESOURCES_GECKO64_PATH) in os.environ["PATH"]: os.environ["PATH"] += os.pathsep + os.path.join(GlobalUtils.RESOURCES_GECKO64_PATH) _driver = webdriver.Firefox(firefox_profile=profile, capabilities=firefox_capabilities) try: selenium_library = BuiltIn().get_library_instance("SeleniumLibrary") selenium_library.register_driver(_driver, "default_ff") except: pass else: raise e return _driver elif browser_name == GlobalUtils.BROWSER_NAMES[Browsers.EDGE]: capabilities = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.EDGE]], "capabilities") options = EdgeOptions() for arg in capabilities: options.set_capability(arg["option"], eval(arg["text"])) options.use_chromium = True # Adding driver to path print("Using EdgeWebDriver") if not GlobalUtils.is_linux(): options.set_capability("platform", "WINDOWS") else: options.set_capability("platform", "LINUX") _driver = Edge(options=options) return _driver elif browser_name == GlobalUtils.BROWSER_NAMES[Browsers.SAFARI]: desired_capabilities = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.SAFARI]], "desired_capabilities") safari_capabilities = DesiredCapabilities.SAFARI for arg in desired_capabilities: safari_capabilities[arg["option"]] = eval(arg["text"]) _driver = webdriver.Safari(desired_capabilities=safari_capabilities) return _driver elif browser_name == GlobalUtils.BROWSER_NAMES[Browsers.OPERA]: desired_capabilities = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.OPERA]], "desired_capabilities") opera_capabilities = DesiredCapabilities.OPERA for arg in desired_capabilities: opera_capabilities[arg["option"]] = eval(arg["text"]) _driver = webdriver.Opera(desired_capabilities=opera_capabilities) return _driver else: return None