def set_browsers(): # set up browsers to be used with webbrowser library ff_path = "C:\\Program Files\\Mozilla Firefox\\firefox.exe" webbrowser.register('Firefox', None, webbrowser.GenericBrowser(ff_path)) edge_path = 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe' webbrowser.register('Edge', None, webbrowser.BackgroundBrowser(edge_path)) brave_path = "C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe" webbrowser.register('Brave', None, webbrowser.GenericBrowser(brave_path))
def main(): try: buildServer = run_local_build_server() while not is_build_server_running(): print "[build server] BOOTING" print "[build server] ONLINE" appInventor = start_appinventor() while not is_app_inventor_running(): print "[app inventor] BOOTING" print "[app inventor] ONLINE" print "[app inventor] OPENING" try: browser = webbrowser.get("chrome") except webbrowser.Error: try: webbrowser.register( "firefox", None, webbrowser.GenericBrowser(os.environ["ProgramFiles"] + r"\Mozilla Firefox\firefox.exe"), 1) browser = webbrowser.get("firefox") except webbrowser.Error: browser = webbrowser.get() browser.open( "http://localhost:8888/_ah/login?continue=http://localhost:8888/") except Exception as e: print type(e) print e finally: taskkill(buildServer.pid) taskkill(appInventor.pid)
def search_song(name): page = 1 webbrowser.register('firefox', None, webbrowser.GenericBrowser('firefox'), 1) finalList = [] while page <= 1: url = 'https://gaana.com/search/' + name f = open(name + '.txt', 'w') source = requests.get(url) # Gets the source code of the page text = source.text soup = BeautifulSoup(text, 'html.parser') ref = True for link in soup.findAll('a', {'class': 'rt_arw'}): # print('hello') # print(link) href = link.get('href') title = link.string final = title + ' - ' + href f.write(final) f.write('\n') if ref == True: webbrowser.get('firefox').open(href) ref = False page += 1
def init_cygwin(): webbrowser.register( 'cygstart', None, webbrowser.GenericBrowser('cygstart'), -1, )
def open_htmlcode_in_browser( html ) : import os , time , webbrowser tmp_file_name = "__temp__.html" webbrowser.register('firefox', None, webbrowser.GenericBrowser('firefox'), 1) with open( tmp_file_name , "w+" ) as f : f.write( html ) webbrowser.get("firefox").open( "file://" + os.popen( "cygpath -w " + os.path.realpath( tmp_file_name ) ).read() ) time.sleep( 2 )
def register_webbrowser_url_hook(): """registers pythons webbrowser module as url_hook""" import webbrowser def open_url(d, link, data): webbrowser.open(link) if sys.platform.startswith("linux"): webbrowser.register("xdg-open", None, webbrowser.GenericBrowser('xdg-open'), update_tryorder=-1) gtk.about_dialog_set_url_hook(open_url, None)
def get_browser(): browser_list = ['galeon', 'mozilla', 'lynx'] for b in browser_list: if test_access(b): browser = webbrowser.GenericBrowser(b + ' %s') webbrowser.register(b, None, browser) return b print 'No Web browser found.' return ''
def register_web_browser(): import webbrowser webbrowser.register( "qtbrowser", None, webbrowser.GenericBrowser( r"python E:\Python\pmgwidgetsproj\pmgwidgets\display\browser\browser.py" )) # c.NotebookApp.browser = 'qtbrowser' webbrowser.get('qtbrowser').open_new('https://cn.bing.com')
def get_browser(): browser_list = [ 'galeon', 'mozilla', 'lynx', 'firefox', 'seamonkey', 'google-chrome' ] for b in browser_list: if test_access(b): browser = webbrowser.GenericBrowser(b + ' %s') webbrowser.register(b, None, browser) return b debug('No Web browser found.') return ''
def show(self, url=None, openon=None): if url: self.go(url) temppath = "%s/%d.html" % (TEMPDIR, time.time()) tempfile = open(temppath, "w") tempfile.write(self.get_html()) tempfile.close() debug(temppath) if not openon: return webbrowser.open(temppath) else: return webbrowser.GenericBrowser(openon).open(temppath)
def webbrowser_register_explorer_exe() -> None: """webbrowser_register_explorer registers `explorer.exe` in the list of browsers under Windows Subsystem for Linux. See https://github.com/online-judge-tools/oj/issues/773 """ # There is an issue that the terminal is cleared after `.open_new_tab()`. The reason is unknown, but adding an argurment `preferred=True` to `webbrowser.register` resolves this issues. # See https://github.com/online-judge-tools/oj/pull/784 if not is_windows_subsystem_for_linux(): return instance = webbrowser.GenericBrowser('explorer.exe') webbrowser.register('explorer', None, instance) # TODO: use `preferred=True` to solve the issue that terminal is cleared, when the version of Python becomes 3.7 or higher
def validate_frob(self, frob, perms): '''Lets the user validate the frob by launching a browser to the Flickr website. ''' auth_url = self.auth_url(perms, frob) try: browser = webbrowser.get() except webbrowser.Error: if 'BROWSER' not in os.environ: raise browser = webbrowser.GenericBrowser(os.environ['BROWSER']) browser.open(auth_url, True, True)
def open_htmlcode_in_browser(html): import webbrowser import os import time # print html tmp_file_name = "__temp__.html" webbrowser.register('firefox', None, webbrowser.GenericBrowser('firefox'), 1) #print webbrowser._tryorder with open(tmp_file_name, "w+") as f: f.write(html) webbrowser.get("firefox").open( "file://" + os.popen("cygpath -w " + os.path.realpath(tmp_file_name)).read()) # time.sleep( 2 ) os.remove(tmp_file_name)
def getChrome(): def getExe(): if sys.platform in ['win32', 'win64']: return find_chrome_win() elif sys.platform == 'darwin': return find_chrome_mac() exe = getExe() if exe: return webbrowser.GenericBrowser(exe) else: webbrowser._tryorder = [ 'google-chrome', 'chrome', "chromium", "chromium-browser" ] try: return webbrowser.get() except webbrowser.Error: return None
def mkbrowseto(self, url): """Create the urwid callback function to open the web browser or call another function with the URL. """ # Try-except block to work around webbrowser module bug # https://bugs.python.org/issue31014 try: browser = os.environ['BROWSER'] except KeyError: pass else: del os.environ['BROWSER'] webbrowser.register(browser, None, webbrowser.GenericBrowser(browser)) try_idx = webbrowser._tryorder.index(browser) webbrowser._tryorder.insert(0, webbrowser._tryorder.pop(try_idx)) def browse(*args): # double ()() to ensure self.search evaluated at runtime, not when # browse() is _created_. [0] is self.search, [1] is self.enter # self.enter prevents opening URL when in search mode if self._get_search()[0]() is True: if self._get_search()[1]() is True: self.search = False self.enter = False elif self.link_open_modes[0] == "Web Browser": webbrowser.open(url) elif self.link_open_modes[0] == "Xdg-Open": run = 'xdg-open "{}"'.format(url) process = Popen(shlex.split(run), stdout=PIPE, stdin=PIPE) elif self.link_open_modes[0] == self.run and self.pipe: process = Popen(shlex.split(self.run), stdout=PIPE, stdin=PIPE) process.communicate(input=url.encode(sys.getdefaultencoding())) else: Popen(self.run.format(url), shell=True).communicate() size = self.tui.get_cols_rows() self.draw_screen(size) return browse
c = get_config() c.NotebookApp.notebook_dir = "C:\\Users\\F121324609\\notebooks" import webbrowser webbrowser.register( 'chrome', None, webbrowser.GenericBrowser( 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe')) c.NotebookApp.browser = 'chrome'
import os import webbrowser os.system(r'make clean') os.system(r'make html') paths = [os.path.join('_build', 'html', fn) for fn in os.listdir(os.path.join('_build', 'html')) if fn.endswith('.html')] for path in paths: lines = [] for line in open(path): if line.startswith('<dd><p>alias of <a class="reference external"'): line = line.split('span')[1] line = line.split('>')[1] line = line.split('<')[0] lines[-1] = lines[-1].replace( 'TYPE</code>', 'TYPE</code><em class="property"> = %s</em>' % line) else: lines.append(line) open(path, 'w').write(''.join(lines)) os.chdir(r'C:\Program Files (x86)\Mozilla Firefox') webbrowser.register('firefox', None, webbrowser.GenericBrowser('firefox'), 1) webbrowser.get('firefox').open_new_tab( r'C:\HydPy\hydpy\docs\_build\html\index.html')
def __init__(self, show_headers, configs): #VBox self.vbox = gtk.VBox() gobject.signal_new("mid_clicked", gtk.VBox, gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, )) self.expander = gtk.Expander() self.evbox = gtk.EventBox() self.evbox.add(self.expander) self.evbox.show_all() self.vbox.pack_start(self.evbox, False, True, 0) self.expander_tooltip = gtk.Tooltips() if show_headers == True: self.expander.set_expanded(True) self.expander_tooltip.set_tip(self.expander, _("Hide Headers")) exp_label = gtk.Label("") self.frame_shown = True else: self.expander.set_expanded(False) self.expander_tooltip.set_tip(self.expander, _("Expand Headers Row")) exp_label = gtk.Label("<b>" + _("Expand Headers Row") + "</b>") self.frame_shown = False exp_label.set_use_markup(True) exp_label.show() self.expander.set_label_widget(exp_label) self.expander.connect("notify::expanded", self.show_hide_headers) self.multiparts_hbox = gtk.HBox() self.vbox.pack_start(self.multiparts_hbox, False, True, 2) self.multiparts_hbox.hide() self.headers_table = gtk.Table(6, 2, False) self.headers_table.set_border_width(2) headers_hbox = gtk.HBox() headers_hbox.pack_start(self.headers_table, True, True, 4) headers_hbox.set_border_width(2) self.x_face_image = gtk.Image() self.x_face_image.set_size_request(48, 48) self.face_image = gtk.Image() self.face_image.set_size_request(48, 48) faces_hbox = gtk.HBox() fake_label = gtk.Label() faces_vbox = gtk.VBox() self.face_frame = gtk.Frame() #self.face_frame.set_shadow_type(gtk.SHADOW_ETCHED_OUT) faces_hbox.set_size_request(48, 48) faces_hbox.pack_start(self.face_image, False, False) faces_hbox.pack_start(self.x_face_image, False, False) faces_vbox.pack_start(self.face_frame, False, False) faces_vbox.pack_start(fake_label, True, True) self.face_frame.add(faces_hbox) headers_hbox.pack_start(faces_vbox, False, False) self.expander.add(headers_hbox) headers_hbox.show_all() self.x_face_image.hide() self.face_image.hide() self.face_frame.hide() self.repopulate_headers() #TextScrolledWindow self.text_scrolledwin = gtk.ScrolledWindow() self.text_scrolledwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.text_scrolledwin.set_shadow_type(gtk.SHADOW_ETCHED_IN) self.vbox.pack_start(self.text_scrolledwin, True, True, 0) self.text_scrolledwin.show() #TextBuffer self.buffer = gtk.TextBuffer() #TextView self.textview = gtk.TextView(self.buffer) self.text_scrolledwin.add(self.textview) self.textview.set_wrap_mode(gtk.WRAP_WORD) self.textview.set_editable(False) self.textview.set_cursor_visible(False) self.textview.show() self.textview.add_events(gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK) self.textview.connect("motion-notify-event", self.mouse_move) self.textview.connect("button-release-event", self.button_press) self.quote1_tag = None self.quote1_tag_bold = None self.quote1_tag_italic = None self.quote1_tag_underline = None self.quote2_tag = None self.quote2_tag_bold = None self.quote2_tag_italic = None self.quote2_tag_underline = None self.quote3_tag = None self.quote3_tag_bold = None self.quote3_tag_italic = None self.quote3_tag_underline = None self.sign_tag = None self.sign_tag_bold = None self.sign_tag_italic = None self.sign_tag_underline = None self.text_tag = None self.text_tag_bold = None self.text_tag_italic = None self.text_tag_underline = None self.tag_url = None self.tag_mid = None self.tag_spoiler = None color = configs["text_color"] self.set_text_color(color) color = configs["quote1_color"] self.set_quote_color(color, 1) color = configs["quote2_color"] self.set_quote_color(color, 2) color = configs["quote3_color"] self.set_quote_color(color, 3) color = configs["sign_color"] self.set_sign_color(color) color = configs["background_color"] self.set_background(color) color = configs["url_color"] self.set_url_color(color) self.set_spoiler_color() self.set_headers_colors(configs["headers_bg_color"], configs["headers_fg_color"]) if configs["custom_browser"] == "True": self.use_custom_browser = True webbrowser.register( "xpn_launcher", None, webbrowser.GenericBrowser(configs["browser_launcher"])) else: self.use_custom_browser = False
def test_synthesize(self): webbrowser = import_helper.import_fresh_module('webbrowser') name = os.path.basename(sys.executable).lower() webbrowser.register(name, None, webbrowser.GenericBrowser(name)) webbrowser.get(sys.executable)
from selenium import webdriver import time import pyautogui from ctypes import windll import win32gui, win32con import win32api from win32api import GetSystemMetrics import webbrowser import execjs from winreg import HKEY_CURRENT_USER, OpenKey, QueryValueEx webbrowser.register( "chrome", None, webbrowser.GenericBrowser( u"C:\\ProgramFiles(x86)\\Google\\Chrome\\Application\\chrome.exe")) chromePath = r'C:\\ProgramFiles(x86)\\Google\\Chrome\\Application\\chrome.exe' webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chromePath)) #这里的'chrome'可以用其它任意名字,如testB,这里将想打开的浏览器保存到'chrome' #webbrowser.get('chrome').open('www.baidu.com',new=1,autoraise=True) webbrowser.open('www.baidu.com', new=2, autoraise=False) # 调用js文件 def get_js(): # f = open("D:/WorkSpace/MyWorkSpace/jsdemo/js/des_rsa.js",'r',encoding='UTF-8') f = open("./chromeVer.js", 'r', encoding='UTF-8') line = f.readline() htmlstr = '' while line: htmlstr = htmlstr + line
import os, sys, time, webbrowser from quixote.directory import Directory from quixote.publish import Publisher, SessionPublisher from quixote.session import Session, SessionManager from quixote.server import simple_server from quixote.errors import AccessError from quixote import get_response, get_user from quixote.html import href, htmltext from quixote.form.form import Form from quixote.form.widget import * webbrowser.register("konqueror", webbrowser.Konqueror) elinks = webbrowser.GenericBrowser('xterm -e elinks %s') lynx = webbrowser.GenericBrowser('xterm -e lynx -accept_all_cookies %s') webbrowser.register("elinks", webbrowser.GenericBrowser, elinks) webbrowser.register("lynx", webbrowser.GenericBrowser, lynx) # second choice class RecognizeExports(type): def __init__(cls, name, bases, dic): super(RecognizeExports, cls).__init__(cls, name, bases, dic) for k in dic: setattr(cls, k, dic[k]) def __setattr__(cls, name, value): if hasattr(value, "_q_exported"): cls._q_exports.append(name) super(RecognizeExports, cls).__setattr__(name, value) # by definition, the root directory is a singleton
# Leading and trailing slashes can be omitted, and will automatically be added. #c.NotebookApp.base_url = '/' ## Specify what command to use to invoke a web browser when opening the notebook. # If not specified, the default browser will be determined by the `webbrowser` # standard library module, which allows setting of the BROWSER environment # variable to override it. #c.NotebookApp.browser = '' print("reading config file") import webbrowser webbrowser.register( 'firefox', None, webbrowser.GenericBrowser( u'C:\\Program Files\\Mozilla Firefox\\firefox.exe')) #webbrowser.register('firefox', None, webbrowser.GenericBrowser(u'C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe')) webbrowser.register( 'chrome', None, webbrowser.GenericBrowser( u'C:\\Users\\nili6\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe' )) #c.NotebookApp.browser = 'firefox' c.NotebookApp.browser = 'chrome' ## The full path to an SSL/TLS certificate file. #c.NotebookApp.certfile = '' ## The full path to a certificate authority certificate for SSL/TLS client # authentication. #c.NotebookApp.client_ca = ''
## The file where the secret key is stored. #c.NotebookNotary.secret_file = '' ## A callable returning the storage backend for notebook signatures. The default # uses an SQLite database. #c.NotebookNotary.store_factory = traitlets.Undefined #------------------------------------------------------------------------------ # KernelSpecManager(LoggingConfigurable) configuration #------------------------------------------------------------------------------ ## If there is no Python kernelspec registered and the IPython kernel is # available, ensure it is added to the spec list. #c.KernelSpecManager.ensure_native_kernel = True ## The kernel spec class. This is configurable to allow subclassing of the # KernelSpecManager for customized behavior. #c.KernelSpecManager.kernel_spec_class = 'jupyter_client.kernelspec.KernelSpec' ## Whitelist of allowed kernel names. # # By default, all installed kernels are allowed. #c.KernelSpecManager.whitelist = set() import webbrowser webbrowser.register('chrome', None, webbrowser.GenericBrowser("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")) c.NotebookApp.browser = 'chrome' c.NotebookApp.open_browser = True # webbrowser.get(chrome_path).open(url)
def register(pathname, key): webbrowser._tryorder += [ key ] webbrowser.register(key, None, webbrowser.GenericBrowser("%s '%%s'" % pathname))
## DEPRECATED use base_url #c.NotebookApp.base_project_url = '/' ## The base URL for the notebook server. # # Leading and trailing slashes can be omitted, and will automatically be added. #c.NotebookApp.base_url = '/' ## Specify what command to use to invoke a web browser when opening the notebook. # If not specified, the default browser will be determined by the `webbrowser` # standard library module, which allows setting of the BROWSER environment # variable to override it. import webbrowser webbrowser.register( 'chrome', None, webbrowser.GenericBrowser(u'/usr/bin/google-chrome-stable')) c.NotebookApp.browser = 'chrome' ## The full path to an SSL/TLS certificate file. #c.NotebookApp.certfile = '' ## The full path to a certificate authority certificate for SSL/TLS client # authentication. #c.NotebookApp.client_ca = '' ## The config manager class to use #c.NotebookApp.config_manager_class = 'notebook.services.config.manager.ConfigManager' ## The notebook manager class to use. #c.NotebookApp.contents_manager_class = 'notebook.services.contents.largefilemanager.LargeFileManager'
def run_browser(url): webbrowser.register('open', webbrowser.GenericBrowser("open '%s'")) webbrowser._tryorder.append('open') webbrowser.open(url)
# GNOME default browser if 'GNOME_DESKTOP_SESSION_ID' in os.environ and webbrowser._iscommand( 'gnome-open'): webbrowser.register('gnome-open', None, webbrowser.BackgroundBrowser( ["gnome-open", "%s"]), update_tryorder=-1) else: # KDE default browser if 'KDE_FULL_SESSION' in os.environ and os.environ[ 'KDE_FULL_SESSION'] == 'true' and webbrowser._iscommand( 'kfmclient'): webbrowser.register('kfmclient', None, webbrowser.GenericBrowser("kfmclient exec '%s' &")) if 'BROWSER' in os.environ: webbrowser._tryorder.insert( len(os.environ['BROWSER'].split(os.pathsep)), 'kfmclient') else: webbrowser._tryorder.insert(0, 'kfmclient') # GNOME default browser if 'GNOME_DESKTOP_SESSION_ID' in os.environ and webbrowser._iscommand( 'gnome-open'): webbrowser.register('gnome-open', None, webbrowser.GenericBrowser("gnome-open '%s' &")) if 'BROWSER' in os.environ: webbrowser._tryorder.insert( len(os.environ['BROWSER'].split(os.pathsep)), 'gnome-open') else: webbrowser._tryorder.insert(0, 'gnome-open')
# read offical doc from https://docs.python.org/3.7/library/webbrowser.html?highlight=webbrowser#webbrowser.get import webbrowser #print(webbrowser._browsers) chrome_path=r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' firefox_path=r'C:\Program Files\Mozilla Firefox\firefox.exe' url = 'https://@10.57.148.34' #webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(path)) webbrowser.register('chrome', None, webbrowser.GenericBrowser(chrome_path)) webbrowser.get('chrome').open_new(url)
import webbrowser import time import os url = 'https://www.bing.com/search?q=reddit' webbrowser.register('edge', None, webbrowser.GenericBrowser(os.environ['ProgramFiles(x86)'] + r'\Microsoft\Edge\Application\msedge_proxy.exe'), preferred=True) webbrowser.open_new(url) with open('binggenlist.txt', 'r') as fh: for line in fh: webbrowser.open(url+'+'+line) time.sleep(2)
def test_is_gui_browser_available_text_browser(mocker): webbrowser_get_mock = mocker.patch('webbrowser.get') webbrowser_get_mock.return_value = webbrowser.GenericBrowser(name='') assert launcher.is_gui_browser_available() is False