def before_all(context): service = Service('drivers\\operadriver.exe') service.start() test_extension = "..\\restman-0.3.nex" b64ext = base64.b64encode(open(test_extension, 'rb').read()) capabilities = { 'operaOptions': { 'binary': 'C:\\Program Files (x86)\\Opera Next\\30.0.1835.49\\opera.exe', 'extensions': [b64ext], }, 'Proxy': { 'proxyType': 'system' } } # Start web server (httpbin FTW!) context.server = subprocess.Popen([sys.executable, '-m', 'httpbin.core']) # Create browser context.browser = webdriver.Remote(service.service_url, capabilities) # Start extension context.browser.get('chrome-extension://fohkgjiaiapkkjjchddmhaaaghjakfeg/index.html') time.sleep(1) # Wait for app to load
def construct(self): # Use the executable file in my desktop to start the chromedriver self.service = Service('/home/abilashbodapati/Desktop/chromedriver') # Start the chromedriver service self.service.start() # Target web-url initialized (Github login-page) self.driver = webdriver.Remote(self.service.service_url)
def initialize_web_driver(): DRIVER_PATH = r"C:\Users\jerem\Desktop\chromedriver.exe" service = Service(DRIVER_PATH) service.start() wd = webdriver.Remote(service.service_url) wd.quit() return DRIVER_PATH
def __init__(self, executable_path="chromedriver", port=0, use_mobile_emulation=False, options=None, service_args=None, desired_capabilities=None, service_log_path=None, chrome_options=None): self.use_mobile_emulation = use_mobile_emulation """ Creates a new instance of the violent chrome driver. Starts the service and then creates new instance of chrome driver. :Args: - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH - port - port you would like the service to run, if left as 0, a free port will be found. - desired_capabilities: Dictionary object with non-browser specific capabilities only, such as "proxy" or "loggingPref". - options: this takes an instance of ChromeOptions - use_mobile_emulation: whether use mobile emulation or not , default is False """ if self.use_mobile_emulation: mobile_emulation = { "deviceMetrics": {"width": 360, "height": 640, "pixelRatio": 3.0}, "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19"} chrome_options = Options() chrome_options.add_argument('disable-infobars') chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) if chrome_options: warnings.warn('use options instead of chrome_options', DeprecationWarning) options = chrome_options if options is None: # desired_capabilities stays as passed in if desired_capabilities is None: desired_capabilities = self.create_options().to_capabilities() else: if desired_capabilities is None: desired_capabilities = options.to_capabilities() else: desired_capabilities.update(options.to_capabilities()) self.service = Service( executable_path, port=port, service_args=service_args, log_path=service_log_path) self.service.start() try: RemoteWebDriver.__init__( self, command_executor=ChromeRemoteConnection( remote_server_addr=self.service.service_url), desired_capabilities=desired_capabilities) except Exception: self.quit() raise self._is_remote = False
def __init__(self, loop=None, pool_size=10): self.loop = loop if loop else asyncio.get_event_loop() self.driver_options = webdriver.ChromeOptions() self.driver_options.add_argument('headless') self.sem = asyncio.Semaphore(pool_size) self.service = Service('chromedriver') self.service.start()
def __init__(self): gc.collect() self.id = random.randint(0, 100) self.c_service = Service('chromedriver') self.c_service.command_line_args() self.c_service.start() self.start_browser() logger.info('Start a browser.')
def init_driver(): # Locate Driver in system Path = "C:\SeleniumDrivers\chromedriver.exe" service = Service(Path) service.start() driver = webdriver.Remote(service.service_url) driver.implicitly_wait(40) return driver
def parse(url): service = Service('/usr/local/bin/chromedriver') service.start() driver = webdriver.Remote(service.service_url) driver.get(url) source_code = driver.page_source driver.quit() return source_code
def startWebDriverService(): """ Starts the web driver as a service, this improves performance and does not require a manual start of the chrome driver. TODO: Make it actually work. """ service = Service(D_PATH_CHROMEDRIVER) service.start() driver = webdriver.Remote(service.service_url) return driver
def __init__(self, executable_path="chromedriver", port=0, options=None, service_args=None, desired_capabilities=None, service_log_path=None, chrome_options=None, keep_alive=True): """ Creates a new instance of the chrome driver. Starts the service and then creates new instance of chrome driver. :Args: - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH - port - port you would like the service to run, if left as 0, a free port will be found. - options - this takes an instance of ChromeOptions - service_args - List of args to pass to the driver service - desired_capabilities - Dictionary object with non-browser specific capabilities only, such as "proxy" or "loggingPref". - service_log_path - Where to log information from the driver. - chrome_options - Deprecated argument for options - keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive. """ if chrome_options: warnings.warn('use options instead of chrome_options', DeprecationWarning, stacklevel=2) options = chrome_options if options is None: # desired_capabilities stays as passed in if desired_capabilities is None: desired_capabilities = self.create_options().to_capabilities() else: if desired_capabilities is None: desired_capabilities = options.to_capabilities() else: desired_capabilities.update(options.to_capabilities()) self.service = Service(executable_path, port=port, service_args=service_args, log_path=service_log_path) self.service.start() try: WebDriver.__init__(self, command_executor=ChromeRemoteConnection( remote_server_addr=self.service.service_url, keep_alive=keep_alive), desired_capabilities=desired_capabilities) except Exception: self.quit() raise self._is_remote = False
def _get_selenium_service(cls) -> Service: if not hasattr(cls, '__selenium_service'): path = ChromeDriverLoader.driver_path if not path: raise AttributeError('Get empty driver path.') service = Service(path) service.start() setattr(cls, '__selenium_service', service) return getattr(cls, '__selenium_service')
def parse(url): service = Service('/usr/local/bin/chromedriver') service.start() driver = webdriver.Chrome(ChromeDriverManager().install()) driver.get(url) time.sleep(120) source_code = driver.page_source driver.quit() return source_code
class DownloadDataSet: def construct(self): # Use the executable file in my desktop to start the chromedriver self.service = Service('/home/abilashbodapati/Desktop/chromedriver') # Start the chromedriver service self.service.start() # Target web-url initialized (Github login-page) self.driver = webdriver.Remote(self.service.service_url) def startChromeService(self, url): # Use the executable file in my desktop to start the chromedriver # service = Service('/home/abilashbodapati/Desktop/chromedriver') # Start the chromedriver service # self.service.start() # Target web-url initialized (Github login-page) # driver = webdriver.Remote(service.service_url) self.driver.get(url) # Maximize the window when the webpage is opened self.driver.maximize_window() def downloadData(self): # By now we are in the webpage for dataset # Click on the Download button self.driver.find_element_by_xpath( "/html/body/main/div[1]/div/div[5]/div[2]/div[1]/div/div/div[2]/div[2]/div[1]/div[2]/a[1]/div/span" ).click() time.sleep(4) # Click on the Signin button self.driver.find_element_by_xpath( "/html/body/main/div[1]/div[1]/div/form/div[2]/div/div[1]/a/li" ).click() time.sleep(5) self.driver.find_element_by_xpath( "/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[1]/div/form/span/section/div/div/div[1]/div/div[1]/div/div[1]/input" ).send_keys('*****@*****.**') time.sleep(20) self.driver.find_element_by_xpath( "/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div/div/span/span" ).click() time.sleep(35) # Click on the Download button again after signed in self.driver.find_element_by_xpath( "/html/body/main/div[1]/div/div[5]/div[2]/div[1]/div/div/div[2]/div[2]/div[1]/div[2]/a[1]/div/span" ).click() time.sleep(1.75) def moveDataToFolder(self): # Unzip the folder from Downloads to Datasets folder. os.system( 'unzip -q /home/abilashbodapati/Downloads/*_bundle_archive.zip -d ./Datasets' )
def initWebdriver(self,initPage:str): self.service = Service(self.driverPath) self.service.start() capabilities = {'acceptSslCerts': True} self.driver = webdriver.Remote(self.service.service_url,capabilities) self.driver.implicitly_wait(5) if initPage is None: self.driver.get(self.url) else: self.driver.get(initPage)
def __init__(self, url): super(Authorization, self).__init__() self.url = url self.chrome_service = Service(ChromeDriverManager().install()) self.firefox_service = Service(GeckoDriverManager().install()) self.options = Options() self.options.add_argument("disable-infobars") self.options.add_argument("--disable-extensions")
def construct(self, project_name, username, password): self.project_name = project_name self.username = username self.password = password # Use the executable file in my desktop to start the chromedriver self.service = Service('/home/abilashbodapati/Desktop/chromedriver') # Start the chromedriver service self.service.start() # Target web-url initialized (Github login-page) self.driver = webdriver.Remote(self.service.service_url)
def __init__(self, savePath): self.savePath = savePath curPath = os.path.dirname(os.path.abspath(__file__)) if platform.system() == "Windows": # self.chrome_service = Service("C:\\Windows\\System32\\chromedriver.exe") self.chrome_service = Service(curPath + "\\..\\Driver\\chromedriver.exe") else: self.chrome_service = Service(curPath + "/../Driver/chromedriver") self.chrome_service.start() self.verify = True
def request_raw_html_from_wiki() -> str: service = Service('./chromedriver/chromedriver') service.start() options = Options() options.add_argument('--headless') options.add_argument('--disable-gpu') driver = webdriver.Remote(service.service_url, options=options) driver.get(stardew_fish_url) page = driver.page_source driver.quit() return page
def setUp(self): print("Setting up") self.__app_url = "http://192.168.56.101/wp-admin" self.__app_logout_url = "http://192.168.56.101/wp-login.php?action=logout" self.username = "******" self.password = "******" driver_path = ChromeDriverManager().install() self.svc = Service(driver_path) self.svc.start() self.driver = webdriver.Remote(self.svc.service_url) self.waiter = WebDriverWait(self.driver, 30)
def init_against_external_service(cls): service = Service(CHROMEDRIVER_BINARY_PATH) service.start() service_url = service.service_url # # for manually-run server # service_url = 'http://localhost:9515' driver = Remote(service_url, DesiredCapabilities.CHROME) return cls(driver)
def __init__(self, chromedriver_path, target_url): chromedriver = chromedriver_path chrome_options = Options() chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') self.s = Service(chromedriver) self.driver = webdriver.Chrome(service=self.s, options=chrome_options) # 设置超时,双重保险 self.driver.set_page_load_timeout(30) self.driver.set_script_timeout(30) self.target_url = target_url
def __init__(self): if len(sys.argv) < 3: self.account = '1778973****' self.password = '******' else: self.account = sys.argv[1] self.password = sys.argv[2] self.url = "https://www.zhihu.com/signin?next=%2Fsettings%2Faccount" # self.url = "https://detail.1688.com/offer/622477660714.html" self.browser = 'chrome' if self.browser == 'chrome': driver_path = "D:\Develop\GeckoDriver\chromedriver_win32\chromedriver.exe" self.c_service = Service(driver_path) self.c_service.command_line_args() self.c_service.start() chrome_options = Options() chrome_options.add_argument('user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"') # chrome_options.add_argument('--headless') # 浏览器不提供可视化页面 chrome_options.add_argument('--no-sandbox') # 取消沙盒模式 chrome_options.add_argument('--disable-gpu') # 禁用GPU加速 chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.add_argument('--start-maximized') # 最大化运行(全屏窗口) chrome_options.add_argument("--incognito") # 隐身模式启动 # chrome_options.add_argument("disable-infobars") # 已弃用 去掉提示:Chrome正收到自动测试软件的控制 # chrome_options.add_experimental_option('useAutomationExtension', False) # 去掉提示:Chrome正收到自动测试软件的控制 # 屏蔽提示:chrome正收到自动测试软件的控制 # 在79(含79)以后的版本无效。谷歌修复了非无头模式下排除“启用自动化”时window.navigator.webdriver是未定义的问题 chrome_options.add_experimental_option('excludeSwitches', ['enable-automation']) # 去掉提示:Chrome正收到自动测试软件的控制 self.driver = webdriver.Chrome(executable_path=driver_path, options=chrome_options) # CDP执行JavaScript 代码 重定义window.navigator.webdriver的值 绕过反爬机制 # 检测机制: # selenium调用驱动打开浏览器,在控制台window.navigator.webdriver会标记FALSE, # 手工正常打开的浏览器控制台window.navigator.webdriver的结果是True self.driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", { "source": """ Object.defineProperty(navigator, 'webdriver', { get: () => undefined }) """ }) elif self.browser == 'firefox': driver_path = "/usr/local/bin/geckodriver" firefox_options = FirefoxOptions() firefox_options.add_argument('--headless') firefox_options.add_argument('--no-sandbox') firefox_options.add_argument('--disable-gpu') # firefox_options.add_argument('--disable-dev-shm-usage') self.driver = webdriver.Firefox(executable_path=driver_path, firefox_options=firefox_options) self.driver.delete_all_cookies()
def start_service(self): try: if self.__chservice == None: cur_dir_path = os.path.dirname(os.path.realpath(__file__)) driver_path = cur_dir_path.split( sep='\\base')[0] + QEEnvironment.get_environment_dict( ).get('BrowserPath') self.__chservice = Service(driver_path) self.__chservice.start() print('Service is started') except: print(traceback.print_exc())
def __init__(self): self.c_service = Service( 'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe' ) self.c_service.command_line_args() self.c_service.start() chrome_options = Options() chrome_options.add_argument('--headless') #不显示界面 #chrome_options.add_argument('--disable-gpu') self.driver = webdriver.Chrome(chrome_options=chrome_options) self.url = "https://music.163.com/#/discover/toplist?id=3778678" '''找到所有热门歌曲的URL和歌曲名称'''
def get_movie_url(url): data_dict = {} i = 0 html = ask_url(url) doc = etree.HTML(html) # 所有级数的a标签和文本 all_url = doc.xpath('//div[@class="fed-play-item fed-drop-item fed-visible"]//ul[@class="fed-part-rows"]/li/a/@href') all_title = doc.xpath('//div[@class="fed-play-item fed-drop-item fed-visible"]' '//ul[@class="fed-part-rows"]/li/a/text()') # 用selenium获取iframe里的src c_service = Service('/usr/bin/chromedriver') c_service.command_line_args() c_service.start() option = webdriver.ChromeOptions() option.add_argument('--headless') option.add_argument('--no-sandbox') option.add_argument('--disable-dev-shm-usage') browser = webdriver.Chrome('/usr/bin/chromedriver', options=option) # print('正在爬取视频链接中') for url in all_url: browser.get('https://kuyun.tv'+url) movie_url = browser.find_element_by_id('fed-play-iframe').get_attribute('src') data_dict[all_title[i]] = movie_url i = i+1 browser.quit() c_service.stop() return data_dict
def punch(StudentId, Name): c_service = Service('/Users/wq//Downloads/chromedriver') c_service.command_line_args() c_service.start() driver = webdriver.Chrome( '/Users/wq/Downloads/chromedriver') # 选择Chrome浏览器 driver.get('http://xsc.sicau.edu.cn/SPCP') # 打开网站 #采用xpath定位 result = driver.find_element_by_xpath('//*[@id="code-box"]') text = result.text driver.find_element_by_xpath('//*[@id="StudentId"]').click() driver.find_element_by_xpath('//*[@id="StudentId"]').send_keys(StudentId) driver.find_element_by_xpath('//*[@id="Name"]').click() driver.find_element_by_xpath('//*[@id="Name"]').send_keys(Name) driver.find_element_by_xpath('//*[@id="codeInput"]').click() driver.find_element_by_xpath('//*[@id="codeInput"]').send_keys(text) driver.find_element_by_xpath('//*[@id="Submit"]').click() driver.find_element_by_xpath('//*[@id="platfrom2"]').click() try: driver.find_element_by_xpath('//*[@id="ckCLS"]').click() driver.find_element_by_xpath('//*[@id="SaveBtnDiv"]/button').click() except: driver.find_element_by_xpath( '//*[@id="layui-layer1"]/div[3]/a').click() driver.quit() c_service.stop()
def setUp(self): super(ChromiumWebDriverFixture, self).setUp() # Import late to avoid hard dependency. from selenium.webdriver.chrome.service import Service as ChromeService service = ChromeService("/usr/lib/chromium-browser/chromedriver", 4444) # Set the LD_LIBRARY_PATH so the chrome driver can find the required # libraries. self.useFixture( EnvironmentVariable("LD_LIBRARY_PATH", "/usr/lib/chromium-browser/libs")) service.start() # Stop service on cleanup. self.addCleanup(service.stop)
def __init__(self, meeting_url): """ * Reads the config file and imports meeting data ! Raises exception in case of no file found / invalid file """ super().__init__() self.email = "*****@*****.**" self.password = "******" self.sleep_time = 12 self.meeting_url = meeting_url self.port = random.randint(1024, 65535) self.service = Service("chromedriver", port=self.port)
class ChromeDriverManager(DriverManager): __chservice = None def launch_browser(self): chrome_option = Options() chrome_option.add_argument("--disable-infobars") chrome_option.add_argument("--start-maximized") chrome_option.add_argument("--disable-popup-blocking") cur_dir_path = os.path.dirname(os.path.realpath(__file__)) chromedriver = cur_dir_path.split( sep='\\base')[0] + QEEnvironment.get_environment_dict().get( 'BrowserPath') os.environ["webdriver.chrome.driver"] = chromedriver driver = webdriver.Chrome(chromedriver, options=chrome_option) driver.get('https://ui.cogmento.com/') def start_service(self): try: if self.__chservice == None: cur_dir_path = os.path.dirname(os.path.realpath(__file__)) driver_path = cur_dir_path.split( sep='\\base')[0] + QEEnvironment.get_environment_dict( ).get('BrowserPath') self.__chservice = Service(driver_path) self.__chservice.start() print('Service is started') except: print(traceback.print_exc()) def stop_service(self): if self.__chservice != None and self.__chservice.is_connectable(): print('Stop service') self.__chservice.stop() def create_driver(self): chrome_option = webdriver.ChromeOptions() chrome_option.add_argument("--disable-infobars") chrome_option.add_argument("--start-maximized") chrome_option.add_argument("--disable-popup-blocking") capabilities = DesiredCapabilities.CHROME.copy() capabilities['browser'] = 'chrome' capabilities = chrome_option.to_capabilities() self.driver = webdriver.Remote(self.__chservice.service_url, desired_capabilities=capabilities) self.edriver = EventFiringWebDriver(self.driver, EventListener()) self.edriver.implicitly_wait( QEEnvironment.get_environment_dict().get('ImplicitWait')) self.edriver.get(QEEnvironment.get_environment_dict().get('URL'))
def inst(phone_number): options = webdriver.ChromeOptions() options.add_argument('--headless') options.add_argument('--no-sandbox') options.add_argument('disable-infobars') options.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'}) options.add_argument("user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36") loc=os.getcwd() serv=Service("%s/path/chromedriver"%loc) driver = webdriver.Chrome(options=options,service=serv) driver.get("https://www.instagram.com/") WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[2]/div/label/input"))).send_keys(phone_number) WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[3]/div/label/input"))).send_keys("thiswill123notbeyourpasswordihope") #/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[4]/button WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[4]/button"))).click() try: name=WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[7]/p"))).text if name=="Sorry, your password was incorrect. Please double-check your password.": print(colored.green("[+]This Phone Number Is Connected To An Instagram Account!")) with open("output/social_media_results.txt","a+") as file: file.write("\n[+]This Phone Number Is Connected To An Instagram Account!"+"\n--------------------------------------------------------------") else: print(colored.red("[-]This Phone Number Is Not Connected To Any Instagram Account!")) with open("output/social_media_results.txt","a+") as file: file.write("\n[-]This Phone Number Is Not Connected To Any Instagram Account!"+"\n--------------------------------------------------------------") except: pass
def main(): options = Options() options.add_argument("--headless") # Run in background os_type = platform.system() service = Service(ChromeDriverManager(log_level=0).install()) driver = webdriver.Chrome(service=service, options=options) url_to_open = sys.argv[-1] if not validators.url(url_to_open): print(str_prefix_err + "Not a URL: '" + url_to_open + "'") sys.exit(1) driver.get(url_to_open) # Open the target URL pic_list = driver.find_element(By.XPATH, "//ul").find_elements(By.XPATH, ".//a") pic_urls = [] for pic in pic_list: pic_url = pic.get_attribute("href").split('?')[0] if pic_url.endswith('.jpg') or pic_url.endswith('.png'): pic_url = pic_url.replace('preview.', 'i.') else: # Unknown exceptions print("Video or non-JPG, not done.") print(pic_url) pic_urls.append(pic_url) # Add formatted URL to array print(" ".join(pic_urls)) # Print all URLs in one line driver.close() # Close the browser options.extensions.clear() # Clear the options that were set sys.exit() # Exit the program