티스토리 뷰

반응형

Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.

Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.

 

아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.

How to open a URL in python

Python에서 어떻게 URL을 열어야 하나요?

 문제 내용 

import urllib

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

 

But when example.com opens it does not render CSS or JavaScript. How can I open the webpage in a web browser?

하지만 example.com을 열면 CSS나 JavaScript가 렌더링되지 않습니다. 이 웹 페이지를 웹 브라우저에서 어떻게 열 수 있을까요?
@error(404)
def error404(error):
    return webbrowser.open('http://example.com')

 

I am using bottle. Giving me the error:

저는 bottle을 사용하고 있는데, 다음과 같은 오류가 발생합니다:
TypeError("'bool' object is not iterable",)

 

 

 높은 점수를 받은 Solution 

with the webbrowser module

webbrowser 모듈을 사용하여
import webbrowser

webbrowser.open('http://example.com')  # Go to example.com

 

 

 가장 최근 달린 Solution 

On Windows

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

 

On macOS

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

 

On Linux

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

 

Cross-Platform

크로스 플랫폼
import webbrowser

webbrowser.open('https://example.com')

 

 

출처 : https://stackoverflow.com/questions/4302027/how-to-open-a-url-in-python

반응형
댓글
공지사항
최근에 올라온 글