How to Scrape Google Light Results
Google Search is the most popular search engine. Today, we have powerful computers, so we can visit Google and get results within seconds.
However, many small devices with limited resources like CPU and RAM are still using Google to get the search results. Google definitely still supports them.
But how? Let's take a closer look to how the browser works.
When you search with Google https://www.google.com/search?q=coffee
, browsers (e.g Chrome, Firefox, Edge, Safari) will download HTML, stylesheets and javascript files.
HTML files will define your search result structure, stylesheets make the web look beautiful, and JavaScript files make the web more dynamic. When using a powerful device to access Google Search, Google will return the full version with these 3 kinds of files and execute them. But when you use less powerful devices, Google will return a simple version of these files, without javascript, to make the page load faster.
For some applications, speed matters, and they need fast Google Search Results to proceed to the next step. Understanding that need, SerpApi provides a very fast Google Light API. Let's scrape some results with this API.
Setting Up a SerpApi Account
SerpApi offers a free plan for newly created accounts. Head to the sign-up page to register an account and complete your first search with our interactive playground. When you want to do more searches with us, please visit the pricing page.
Once you are familiar with all the results, you can utilize SERP APIs using your API Key.
Scrape your first Google Light Search result with SerpApi
Head to the Google Light Search API from the documentation on SerpApi for details.
Let's find all organic results for "Christmas Tree" . The data contains: "position", "title", "link", "snippet", and more. You can also scrape more information with SerpApi.
First, you need to install the SerpApi client library.
pip install google-search-results
Set up the SerpApi credentials and search.
from serpapi import GoogleSearch
import os, json, csv
params = {
'api_key': 'YOUR_API_KEY', # your serpapi api
'engine': 'google_light', # SerpApi search engine
'q': 'Christmas Tree'
}
To retrieve Google Light Search Results for a query, you can use the following code:
results = GoogleSearch(params).get_dict()['organic_results']
You can store Google Light Search Results JSON data in databases or export them to a CSV file.
import csv
header = ["position", "title", "link", "snippet"]
with open("google_light_results.csv", "w", encoding="UTF8", newline="") as f:
writer = csv.writer(f)
writer.writerow(header)
for item in results:
writer.writerow([item.get('position'), item.get('title'), item.get('link'), item.get('snippet')])
This example uses Python, but you can also use all your favorite programming languages like Ruby, NodeJS, Java, PHP, and more.
If you have any questions, please feel free to contact me.