how to open a url in python

后端 未结 7 1792
夕颜
夕颜 2020-12-22 19:01
import urllib

fun open():
    return urllib.urlopen(\'http://example.com\')

But when example.com opens it does not render css or js. How can I ope

相关标签:
7条回答
  • 2020-12-22 19:38

    You could also try:

    import os
    os.system("start \"\" http://example.com")
    

    This, other than @aaronasterling ´s answer has the advantage that it opens the default web browser. Be sure not to forget the "http://".

    0 讨论(0)
  • 2020-12-22 19:40

    Here is another way to do it.

    import webbrowser
    
    webbrowser.open("foobar.com")
    
    0 讨论(0)
  • 2020-12-22 19:45

    with the webbrowser module

    import webbrowser
    
    webbrowser.open('http://example.com')  # Go to example.com
    
    0 讨论(0)
  • 2020-12-22 19:46
    import webbrowser  
    webbrowser.open(url, new=0, autoraise=True)
    

    Display url using the default browser. If new is 0, the url is opened in the same browser window if possible. If new is 1, a new browser window is opened if possible. If new is 2, a new browser page (“tab”) is opened if possible. If autoraise is True, the window is raised

    webbrowser.open_new(url)
    

    Open url in a new window of the default browser

    webbrowser.open_new_tab(url)
    

    Open url in a new page (“tab”) of the default browser

    0 讨论(0)
  • 2020-12-22 19:47

    I think this is the easy way to open a URL using this function

    webbrowser.open_new_tab(url)
    
    0 讨论(0)
  • 2020-12-22 19:52

    On window

    import os
    os.system("start \"\" https://example.com")
    

    On macOS

    import os
    os.system("open \"\" https://example.com")
    

    On Linux

    import os
    os.system("xdg-open \"\" https://example.com")
    

    Cross-Platform

    import webbrowser
    
    webbrowser.open('https://example.com')
    
    0 讨论(0)
提交回复
热议问题