by
0
6
384k
6
Top 1% !
Popular
Tagged
Easy-to-find
Specified
OpenSource
Popularity: 1216th place
Created
Modified Oct 30, 2013

Published on:

Architecturex86_64
LanguagePython
LicenseMIT_X11

How to fetch Internet Resources Using urllib2 in python

urllib2 is a Python module for fetching URLs (Uniform Resource Locators).

It offers a simple interface, based on the urlopen function. 
This method is capable of fetching URLs using a variety of different protocols.

In this example you can see a specific exception handlers for HTTPError and URLError.
post this code
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/12151/How-to-fetch-Internet-Resources-Using-ur?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
import os, urllib2 def getURLResult(): try: intRes = urllib2.urlopen("http://your_URL") except urllib2.HTTPError, e: print "HTTPError Error: " + str(e.code) except urllib2.URLError, e: print "URLError Error: " + str(e.reason) print "ok"
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus