Introduction
When making purchasing decisions for new products, it's always a good idea to do a bit of research beforehand. Depending on the type of product you're looking for, you might find yourself performing the same set of searches to quickly surface any red flags (and green flags) about the product in particular.
Let's say we're wanting to buy a new car. We'll start with the Toyota Camry, one of the best selling cars in the United States.
There's a few searches you can do to help find out if there's any red flags you might want to know about:
"toyota camry common problems"
"toyota camry recalls"
"toyota camry broke down"
"toyota camry stalling"
You could also do some searches that might tell you how happy owners are with their cars:
"toyota camry" "great decision"
"toyota camry" "horrible decision"
"toyota camry" "very comfortable"
You may also find yourself looking at owner reviews or automotive magazine/website reviews with:
"toyota camry" reviews
Now imagine you're wanting to do this on demand and come back with your own scoring system based on what or how many results come back.
Vehicle Scoring Demo
We're going to make a very basic vehicle scoring demo using the same sort of searches mentioned above, but feel free to make tweaks as you go along; there's no reason you can't make some minor changes to make this work to score any other products such as coffee machines, golf clubs, or garden tools!
Prerequisites
- A SerpApi API key - you can sign up for the free plan to follow along
- Python 3.7+ installed (or your favorite programming language)
- Five minutes of spare time
Getting Started
Get your API key from the SerpApi account page.
Install the SerpApi Python package:
$ pip install google-search-results
Note: if you're not following along with Python, you can install the SerpApi package for your favorite language and adjust the examples as necessary to suit
Create a new script vehicle-research.py
and add the following to the top:
from serpapi import GoogleSearch
Defining Searches
Define the searches you would like to use as positive and negative markers in your script, here are what I've used:
def negative_queries(vehicle):
return [
f"\"{vehicle} transmission issue\"",
f"\"{vehicle} engine issue\"",
f"\"{vehicle} recalls\"",
f"\"{vehicle} broke down\"",
f"\"{vehicle} problems\"",
f"\"{vehicle} warranty problem\"",
f"\"{vehicle} unreliable\"",
f"\"{vehicle} faults\"",
f"\"{vehicle} common problems\"",
f"\"{vehicle} stalling\"",
f"\"{vehicle}\" \"catastrophic failure\"",
f"\"{vehicle}\" \"i regret buying\"",
f"\"{vehicle}\" \"horrible decision\"",
]
def positive_queries(vehicle):
return [
f"\"{vehicle} works great\"",
f"\"{vehicle} is amazing\"",
f"\"happy with my {vehicle}\"",
f"\"{vehicle}\" \"great decision\"",
f"\"{vehicle}\" \"very comfortable\"",
f"\"{vehicle}\" \"runs very well\"",
f"\"{vehicle}\" \"amazing value\"",
f"\"{vehicle}\" \"would recommend you buy\"",
]
Getting Result Counts
For simplicity's sake, we're going to use the result count in our scoring instead of anything more complex at this stage.
Add the following method to your script:
def get_result_count(query):
search = GoogleSearch({
"q": query,
"location": "United States",
"api_key": "<your secret api key>",
})
result = search.get_dict()
if result.get("search_information", {}).get("spelling_fix"):
return 0
return int(result.get("search_information", {}).get("total_results", 0))
You'll also notice that we're returning 0
if there is something found at search_information.spelling_fix
, this is because we're not interested in results that aren't for our exact search queries.
Scoring Vehicles
Now we'll define the vehicle that we're searching for. We'll pick the 2022
year model for the Toyota Camry to make it a bit more targeted:
vehicle = "2022 Toyota Camry"
After that, we're going to add the searching and marker tallying logic.
To keep it simple, we're going to add a negative marker for each of our negative searches that return any results, a positive marker for each positive search that returns any results, and we'll tally them up at the end for our final score.
Here's the code we're using to do that:
negative_markers = 0
positive_markers = 0
print()
print(f"Searching for vehicle: {vehicle}")
print()
print("Negative results found:")
for query in negative_queries(vehicle):
count = get_result_count(query)
if count > 0:
negative_markers += 1
print(f"{query}: {count}")
if negative_markers == 0:
print("none")
print()
print("Positive results found:")
for query in positive_queries(vehicle):
count = get_result_count(query)
if count > 0:
positive_markers += 1
print(f"{query}: {count}")
if positive_markers == 0:
print("none")
print()
print(f"Negative markers: {negative_markers}")
print(f"Positive markers: {positive_markers}")
print(f"Score: {positive_markers - negative_markers}")
Then finally we'll run our newly created script and see how it goes!
$ python vehicle-research.py
You should see results similar below:
Searching for vehicle: 2022 Toyota Camry
Negative results found:
"2022 Toyota Camry recalls": 8530
"2022 Toyota Camry problems": 10
"2022 Toyota Camry common problems": 2
"2022 Toyota Camry" "catastrophic failure": 384
"2022 Toyota Camry" "i regret buying": 3800
"2022 Toyota Camry" "horrible decision": 1
Positive results found:
"2022 Toyota Camry works great": 1
"happy with my 2022 Toyota Camry": 2
"2022 Toyota Camry" "great decision": 1110
"2022 Toyota Camry" "very comfortable": 18900
"2022 Toyota Camry" "runs very well": 1170
"2022 Toyota Camry" "amazing value": 4010
"2022 Toyota Camry" "would recommend you buy": 2
Negative markers: 6
Positive markers: 7
Score: 1
More Ideas
You can adjust the scoring mechanism to suit your purposes or depending on the type of product.
Here are a few ideas you could tinker with:
- Score based on competing queries - e.g. whichever search has more results out of
"i love my toyota camry"
vs"i hate my toyota camry"
- Weight the score depending on the number of results - e.g.
+1
for 1 result or+5
for>1000
reults - Use editorial reviews (i.e. magazines, newspapers, etc) and user reviews to change the scoring
- Scope some or all of the searches to particular websites - e.g.
site:reddit.com "toyota camry broke down"
- and many more!
Source Code
You can also take a look at the accompanying repository on GitHub for the full Python code (plus a bonus addition that includes editorials reviews in the scoring) or the equivalent Ruby code.