title: What's the fastest way to check a webpage's status?
body: <p>I'm trying to check a webpage's status with Python. I've done timers to test, but nothing yields anything much better than the other. The worst and best only differ by 20%. I really just need the response code, not the HTML source. There are 3 response codes that I will handle: 200, 403, 404.</p>
  
  <p>Method 1 is mine but the others were found here: <a href="https://stackoverflow.com/questions/1949318/checking-if-a-website-is-up-via-python">Checking if a website is up via Python</a></p>
  
  <p><strong>Method 1</strong>: Right now, I'm using mechanize to open the URL with a try and except. If it's a 200, it'll go through fine but if it's 403/404, it'll run the except. This works fine, but it's not very fast. The average speed is 0.00276</p>
  
  <p><strong>Method 2</strong>: Using urllib, I get about the same time as python. The average speed is 0.00227. Here's the code for that, it's just a one liner.</p>
  
  <pre><code>print urllib.urlopen("http://www.stackoverflow.com").getcode()
  </code></pre>
  
  <p><strong>Method 3</strong>: I think this httplib method would be fastest, but it only checks domains, it doesn't check individual pages of a domain, so it didn't work in my case. The code for that is:</p>
  
  <pre><code>conn = httplib.HTTPConnection("www.python.org")
  conn.request("HEAD", "/")
  r1 = conn.getresponse()
  print r1.status, r1.reason
  </code></pre>
  
  <p><strong>Method 4</strong>: This method uses requests.head and it has an average speed of 0.00246. The code is:</p>
  
  <pre><code>r = requests.head("http://www.stackoverflow.com")
  print r
  </code></pre>
  
  <p>Does anyone know a more efficient way of checking a webpage's status in python?</p>