You could try to do this with getcode()
from urllib
import urllib.request
print(urllib.request.urlopen("https://www.stackoverflow.com").getcode())
200
For Python 2, use
print urllib.urlopen("http://www.stackoverflow.com").getcode()
200
More Related Contents:
- Ideal method for sending multiple HTTP requests over Python? [duplicate]
- How to limit download rate of HTTP requests in requests python library?
- urllib2.HTTPError: HTTP Error 403: Forbidden
- How do I get the path and name of the file that is currently executing?
- Python recursive folder read
- How can I sandbox Python in pure Python?
- How to make a Python script run like a service or daemon in Linux
- Driving Excel from Python in Windows
- A good way to get the charset/encoding of an HTTP response in Python
- Python urllib2 with keep alive
- Python ‘requests’ library – define specific DNS?
- Putting a `Cookie` in a `CookieJar`
- Python Requests package: Handling xml response
- How to encode UTF8 filename for HTTP headers? (Python, Django)
- Python urllib2 Progress Hook
- In Python, how do I decode GZIP encoding?
- Why am I getting this error in python ? (httplib)
- How do I send a POST request as a JSON?
- Using Flask, how do I modify the Cache-Control header for ALL output?
- python how to decode http response
- How to implement retry mechanism into python requests library?
- How to scrape a website that requires login first with Python
- Python: How do I get key/value pairs from the BaseHTTPRequestHandler HTTP POST handler?
- Download file using partial download (HTTP)
- Why am I getting httplib.BadStatusLine in python?
- Does Django have a way to open a HTTP long poll connection?
- How to catch 404 error in urllib.urlretrieve
- WinError 10049: The requested address is not valid in its context
- Is there any way to do HTTP PUT request in Python?
- How do I set HTTP headers using Python’s urllib?