Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6232945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:12:30+00:00 2026-05-24T10:12:30+00:00

I want to display a random link + its name from an RSS feed.

  • 0

I want to display a random link + its name from an RSS feed.
The code I use is:

def updateFeed(url):
    query_args = { 'q': 'http://news.google.com/?output=rss', 'v':'1.0', 'num': '15', 'output': 'json' }
    qs = urllib.urlencode(query_args)
    loader = 'http://ajax.googleapis.com/ajax/services/feed/load'
    loadurl = '%s?%s' % (loader, qs)
    logging.info(loadurl)
    result = urlfetch.fetch(url=loadurl,
                            headers={'Referer': '...'})
    if result.status_code == 200:
                news = simplejson.loads(result.content) 

I do get response data in JSON but I don’t know how to randomly select an item. Can you please advice?

{u'responseData': {u'feed': {u'feedUrl': u'http://news.google.com/?output=rss', u'description': u'Google News', u'author': u'', u'title': u'Top Stories - Google News', u'link': u'http://news.google.com/news?pz=1&amp;jfkl=true&amp;ned=us&amp;hl=en', u'entries': [{u'publishedDate': u'Tue, 02 Aug 2011 08:51:09 -0700', u'title': u'House Approved Debt Bill Faces Final Hurdle - NY1', u'author': u'', u'content': u'<table border="0" cellpadding="2" cellspacing="7" style="vertical-align:top"><tr><td width="80" align="center" valign="top"><font style="font-size:85%;font-family:arial,sans-serif"><a href="http://news.google.com/news/url?sa=t&amp;fd=R&amp;usg=AFQjCNEyXr4E-W9lA8bsV4_Zslubxd-6_g&amp;url=http://www.theglobeandmail.com/news/world/americas/little-sign-of-compromise-ahead-of-us-default-deadline/article2114420/"><img src="http://nt3.ggpht.com/news/tbn/dyFy2sz6rKRlJM/6.jpg" alt="" border="1" width="80" height="80"><br><font size="-2">Globe and Mail</font></a></font></td><td valign="top"><font style="font-size:85%;font-family:arial,sans-serif"><br><div style="padding-top:0.8em"><img alt="" height="1" width="1"></div><div><a 

Edit: It works now almost perfect and I learn about JSON doing this:

def updateFeed(url):
    query_args = { 'q': 'http://news.google.com/?output=rss', 'v':'1.0', 'num': '15', 'output': 'json' }
    qs = urllib.urlencode(query_args)
    loader = 'http://ajax.googleapis.com/ajax/services/feed/load'
    loadurl = '%s?%s' % (loader, qs)
    logging.info(loadurl)
    result = urlfetch.fetch(url=loadurl,headers={'Referer': '...'})
    if result.status_code == 200:
        news = simplejson.loads(result.content) 

        """ not working, using random.randrange instead
        some_key = random.choice(news.keys())
        something = news[some_key]
        """
        i = random.randrange(0,10)#to do: instead of 10, it should be number of entries
        title = news[u'responseData'][u'feed'][u'entries'][i][u'title']
        link = news[u'responseData'][u'feed'][u'entries'][i][u'link']
    return mark_safe('<a href="%s">%s</a>' % (link, title))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:12:31+00:00Added an answer on May 24, 2026 at 10:12 am

    When you load JSON in Python, it’s converted into (nested) dicts and lists. { ... } objects become dictionaries, and [ ... ] comma-separated items become lists.

    For example, to get the feed URL, you can do:

    feedUrl = news[u'responseData'][u'feed'][u'feedUrl']
    

    To select a random element from a dictionary, you can do:

    import random
    some_key = random.choice(news.keys())
    something = news[some_key]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display 1 random record from a database based on the week.
I want to display a random record from the database for a certain amount
I have a smarty template, that I want to display a random sentence on
I want to display the TIME field from my mysql table on my website,
I want to display tabular type data, but it will not be coming from
i want to display a set of random questions when the user presses keypad_hash
i want to display random no in the applet as long as the applet
I'm building a simple random div displayer. I want to display one random li
I want a web page to display several random images on load. I've thought
HI, I want to display 20 random images at a time over Activity screen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.