Google suggest Keywords

If we enter any keyword in google search box , we will get a set of suggestions from google matching the input keyword for us to use as autocomplete.
Using this keyword we can collect the suggestions from google by using BeautifulSoup.

Here is the link to get XML data from google.

Check xml data from google
import requests
from bs4 import BeautifulSoup
str1='Python' # search string 
link = ""+str1
content = requests.get(link)
soup = BeautifulSoup(content.text, "xml") # creating bs4 object 
for d in soup.find_all('CompleteSuggestion'): # loop through all suggestions 
Output is here
python online compiler
python download
python interview questions
python compiler
python tutorial
python programming
python w3schools
python interview questions for freshers
python basics

User Input Search string

#str1='Python' # search string 
str1=input("Enter keyword: ") # user input for search string

Using multiple keywords

import requests
from bs4 import BeautifulSoup
for s in kw:
    link = ""+s
    content = requests.get(link)
    soup = BeautifulSoup(content.text, "xml")
    for d in soup.find_all('CompleteSuggestion'):
        #print(d.suggestion['data']) # printing the data
        my_list.append(d.suggestion['data']) # adding to list
We can store the above data in a google sheet, add this part at the end of the above code.
Python- Pygsheets
import pygsheets
path='G:\\My drive\\testing\\google-sheet\\creds1.json'
Before scraping read the website’s legal use of data and avoid frequent request for data to website.

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer