Using Python to search string where a number iterates
Question: I'm trying to write a script that will search a string in google, loop and
iterate the number in the string, and print the top links. I have this:

    
    
    import urllib.parse
    import urllib.request
    import json as m_json
    
    for x in range(3, 5):
        query = '"Amazon Best Sellers Rank: #' + str(x) + ' in Kitchen & Dining": Amazon.com'
        query = urllib.parse.urlencode ( { 'q' : query } )
        response = urllib.request.urlopen ( 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&' + query ).read().decode()
        json = m_json.loads ( response )
    results = json [ 'responseData' ] [ 'results' ]
    for result in results:
        title = result['title']
        url = result['url']   # was URL in the original and that threw a name error exception
        print ( title + '; ' + url )
    

I'm getting this error: "TypeError: 'NoneType' object is not subscriptable" on
line 10, results = ...


Answer: **Same question** Was posted by you beforetwo months and now again you are
posting that [Link to your
question.](http://stackoverflow.com/questions/35023259/python-script-that-
runs-an-iterating-google-search-and-prints-top-results-and-li)

And by the way the answer to your question is also has been provided already
on stackoverflow.

But again I am posting the code for you . And using your code only I am
getting the desired result in Python 2.7 .

    
    
    import urllib
    import json as m_json
    
    for x in range(3, 5): 
        query = 'x mile run'
        query = urllib.urlencode ( { 'q' : query } )
        response = urllib.urlopen ( 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&' + query ).read()
        json = m_json.loads ( response )
        results = json [ 'responseData' ] [ 'results' ]
        for result in results:
            title = result['title']
            url = result['url']   
            print ( title + '; ' + url )
    

