import requests
import json


def search(keyword, limit=20):
    """
        Search is the iTunes podcast directory for the given keywords.
        Parameter:
            keyword = A string containing the keyword to search.
            limit: the maximum results to return,
            The default is 20 results.
        returns:
            A JSON object.
    """
    keyword = keyword.replace(' ', '+')  # Replace white space with +.
    # Set user agent.
    user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
    headers = {'User-Agent': user_agent}
    # ITunes podcast search URL.
    itunesurl = 'https://itunes.apple.com/search?term=%s&country=us&limit=%d&entity=podcast' % (keyword, limit)
    req = requests.get(itunesurl, headers=headers)
    return json.loads(req.text)