Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
つまり、200 を返す場合は True を出力します。そうでなければ、偽。
どうすればそれを検出できますか?
ありがとう。
requestsライブラリを使用して Web サイトにアクセスすることをお勧めします。
requests
>>> r = requests.get('http://example.com') >>> r.status_code 200
status_codeが 200 でない場合、または例外が発生した場合は、正しく機能していません。関連する例外 ( などrequests.exceptions.Timeout)については、こちらとこちらをご覧ください。
status_code
requests.exceptions.Timeout
関数urllib2.urlopenを次のように使用できます。
>>> import urllib2 >>> print urllib2.urlopen("http://www.example.com").getcode() 200