Created
          April 16, 2013 11:37 
        
      - 
      
- 
        Save ss81/5395271 to your computer and use it in GitHub Desktop. 
    Feed Parser
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import urllib2 | |
| import feedparser | |
| import time | |
| import sys | |
| url = 'http://www.zurnal24.si/index.php?ctl=show_rss' | |
| opener = urllib2.build_opener() | |
| opener.addheaders = [('User-Agent', 'Mozilla/5.0')] | |
| # Try to connect a few times, waiting longer after each consecutive failure | |
| MAX_ATTEMPTS = 8 | |
| for attempt in range(MAX_ATTEMPTS): | |
| try: | |
| request = opener.open(url) | |
| break | |
| except urllib2.URLError, e: | |
| sleep_secs = attempt ** 2 | |
| print >> sys.stderr, 'ERROR: %s.nRetrying in %s seconds...' % (e, sleep_secs) | |
| time.sleep(sleep_secs) | |
| response = request.read() | |
| feed = feedparser.parse(response) | |
| title = feed['channel']['title'] | |
| print title | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment