import csv import requests result = '' for i in range(195): list_json = requests.get(url, headers={ 'X-Requested-With': 'XMLHttpRequest', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36', 'Accept': '*/*', 'Host': 'www.google.com', 'Connection': 'keep-alive', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache' }).json() result += list_json['snippets-obj'] try: file = open('test.html', 'w') except IOError: file = open('test.html', 'w') html = '{}'.format("".join(result.encode('UTF-8').strip())) file.write(html) file.close()