Skip to content

Instantly share code, notes, and snippets.

@cristiano74
Last active August 21, 2018 15:34
Show Gist options
  • Save cristiano74/615c94ec83471b2fd79f216c73838379 to your computer and use it in GitHub Desktop.
Save cristiano74/615c94ec83471b2fd79f216c73838379 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 21 13:07:31 2018
@author: cristianodalfarra
"""
#!/usr/bin/env python
# coding:utf-8
# =============================================================================
# # https://www.quora.com/How-can-I-scrape-Googles-autocomplete-suggestions-with-python
#
# import requests, json
# URL="http://suggestqueries.google.com/complete/search?client=firefox&q=dove * obbligazioni&hl=it"
# headers = {'User-agent':'Mozilla/5.0'}
# response = requests.get(URL, headers=headers)
# result = json.loads(response.content.decode('utf-8'))
# print(result)
#
#
#
# =============================================================================
# https://www.bronco.co.uk/our-ideas/content-topics/
import requests
import json
# here you include your main terms, this can be as many as you like
terms = ['obbligazioni']
# these are just 'variations' which are appended to the start of your 'terms'
variations = [
'quali * ' ,
'sono * ' ,
'possono * ' ,
'può *'
'come * ' ,
'quanto * ' ,
'perchè * ' ,
'dove * ' ,
'quando * ' ,
'chi * ' ,
'cosa * ' ,
'a cosa * ' ,
'che * '
'chi è * ' ,
'chi sono * ' ,
'ha * ' ,
'hanno * ' ,
'deve * ' ,
'dovrebbe * '
]
for term in terms:
for variant in variations:
# request api
r=requests.get('http://suggestqueries.google.com/complete/search?client=firefox&q={}{}'.format(variant, term))
# grab returned text loading as json
parsed_json = json.loads(r.text)
# print each parsed item
print (parsed_json[0])
for i in parsed_json[1]:
print ('- ', i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment