fork(1) download
  1. import sys
  2. import urllib2
  3. import urlparse
  4.  
  5. URL = sys.stdin.read().strip()
  6.  
  7. # parse url
  8. url = urlparse.urlsplit(URL)
  9. newurl = urlparse.urlunsplit(url[:3]+('',''))
  10. print newurl
  11.  
  12. # try to access the page
  13. try:
  14. resp = urllib2.urlopen(newurl)
  15. except IOError, e:
  16. print "error: can't open %s, reason: %s" % (newurl, e)
  17. else:
  18. print "success, status code: %s, info:\n%s" % (resp.code, resp.info()),
  19.  
Success #stdin #stdout 0.06s 9560KB
stdin
http://w...content-available-to-author-only...t.com/blogs/answer-sheet/post/report-we-still-dont-know-much-about-charter-schools/2012/01/13/gIQAxMIeyP_blog.html?wprss=linkset&tid=sm_twitter_washingtonpost
stdout
http://w...content-available-to-author-only...t.com/blogs/answer-sheet/post/report-we-still-dont-know-much-about-charter-schools/2012/01/13/gIQAxMIeyP_blog.html
error: can't open http://w...content-available-to-author-only...t.com/blogs/answer-sheet/post/report-we-still-dont-know-much-about-charter-schools/2012/01/13/gIQAxMIeyP_blog.html, reason: <urlopen error [Errno -3] Temporary failure in name resolution>