Script to get the TOP and TRENDING SEARCH RESULTS
The below script helps for Youtubers and other social media users to make their post, story or reels to be in top of the search results, as well as be in trending.
Here we are using Google's toolbar and we are just passing the search query over there and it returns back with XML.
Google Toolbar Search URL : https://google.com/complete/search?output=toolbar&gl=eg=&q=
Say if you want to search the trending keywords of Digital Marketing
Example: https://google.com/complete/search?output=toolbar&gl=eg=&q=digital%20marketing
It returns back with the below xml
Now, if you take a look at the suggestion data, those are your targeted words to add in your post,story or even in blog labels
import requests
import xml.etree.ElementTree as ET
## This function uses the XML etree functionality to parse the xml content
def search_keyword(kw):
url = 'https://google.com/complete/search?output=toolbar&gl=eg=&q='+str(kw)
resp = requests.get(url)
mytree = ET.fromstring(resp.content)
trend_keywords = []
for ele in list(mytree):
trend_keywords.append(ele[0].attrib['data'])
return trend_keywords
search_keyword('Machine Learning')
Output:
['machine learning',
'machine learning definition',
'machine learning algorithms',
'machine learning interview questions',
'machine learning projects',
'machine learning course',
'machine learning is a subset of',
'machine learning tutorial',
'machine learning types',
'machine learning projects for final year']
I hope the functionality is pretty clear.
I have imported xml.etree function and that gets the resp.content into the fromstring function. So, by iterating the tree element, we can access the attrib within the xml tags and that retrieves the text from it.
Our previous post : Generic website data extraction

No comments