Recently I got an email from my friend John Simpson. He was having a search problem and thought I might be able to help him out. I was, and wanted to share with you what I did, because a) you might be able to use it too and b) it’s not often in my Internet experience that you end up solving a problem using a method that was popular over ten years ago.
Here’s John’s problem: he does regular Google searches of a particular kind, but finds that with most of these searches he gets an overwhelming number of results from just a couple of sites. He wants to consistently exclude those sites from his search results, but he doesn’t want to have to type in the exclusions every time.
What’s a Bookmarklet?
What I did was create a bookmarklet that excluded the sites from which he didn’t want results. When he clicks on the bookmarklet, it prompts him for his search term and then runs the search.
I tested the bookmarklet on Chromium, Chrome, and Firefox, and it works fine if you allow pop-ups (unfortunately I couldn’t find a way to just whitelist local pop-ups.)
Let’s walk through how I did it. Maybe there’s a way you can use this!
Creating a Bookmarklet
There are still some bookmarklet places hanging around the Web, though the last time I saw it being mentioned and worked with a lot was 2005 or so. Squarefree’s bookmarklets list is one of those sites (and its front page was last updated in 2004!) The search engine bookmarklets page has a bookmarklet for searching Google, which is what I based this on — I am eternally grateful to Jesse Ruderman for keeping his site up and not making me dig through my own archives trying to find code.
Here’s the Squarefree bookmarklet code:
Basically the bookmarklet checks to see if you’ve highlighted text on a Web page, and if you have it runs that as a Google search. If not it prompts you to enter your own search term.
This is the part we need to change:
That is a plain Google search, but John wants to exclude all search results from Pinterest.com and experts-exchange.com. We need to incorporate those exclusions. That will take three steps.
Step One: Run the Search You Want to See
I’m going to pretend to be John and run a search for cows, excluding Pinterest and Experts Exchange. (DISCLAIMER: I have no idea of John searches for cows or not.) My query will look like this.
cows -site:pinterest.com -site:experts-exchange.com
The Google search result URL will look something like this (I removed some of the cruft that Google adds):
(You’ll notice that the URL reads -site%3Apinterest.com instead of -site:pinterest.com. That’s because the colon (:) symbol has been encoded in the URL. You can learn more about URL encoding here.)
Step Two: Extract the search modifiers from the result URL
If you’re doing something super esoteric, the Google search result URL might be a little hard to read, or the URL encoding might throw you off if you’re using a lot of special characters. But generally you can map what you’re seeing in the search results to the search terms you were looking for. In this case I want to put -site%3Apinterest.com -site%3Aexperts-exchange.com in my Google search result URL of the bookmarklet.
Step Three: Modify the Bookmarklet
The bookmarklet’s Google result URL looks like this, as I noted:
I want to integrate the search result modifiers into this URL, but at the same time I want to make sure the URL ends in q=, because when John is prompted for a search term, his input will go after that last q. I want to put my modifiers before that prompt.
“q” stands for query, I believe, and you can have more than one in a Google search result URL, so I put one at the beginning for my search modifiers and left one at the end.
I added in the query modifiers -site%3Aexperts-exchange.com+-site%3Apinterest.com , then added an ampersand (&) to let Google know there would be another query in the search, and then put the q= for user-input search terms.
How does this all look in one place?
Now we have a bookmarklet that John can install and he’ll nevermore have to look at Pinterest or Experts Exchange in his search results. Let’s install this in Firefox. Three steps again.
Step One: Install the Bookmarklet
Open up Firefox and make sure your Bookmarks Toolbar is visible. (You can do this without having the bookmarks bar visible, but having it visible makes this part easier.)
In the Bookmarks Toolbar you might see a bookmark called Getting Started, from Firefox. I’m going to edit that one to turn it into this bookmarklet. (I find it’s easier to just bookmark a page and then edit it to make a bookmarklet, as opposed to trying to make one “from scratch.”)
Right-click that Getting Started bookmark on your toolbar and click Properties:
(Don’t ask me why I’m searching for pancakes. I think it’s because it’s almost 7:30 and I haven’t had dinner yet.)
Save that. You should now have a Firefox bookmark called No Pinterest, No Experts Exchange Google Search. Click on it and you should get a window prompting you for your Google Search.
Enter your search, click OK, and — there you go!
This is a somewhat simple implementation of a modified Google search — it just excludes two sites. But you could go a lot further. You could include multiple sites or include/exclude based on an URL pattern. You could restrict a search to just titles if you do general searches that tend to get too many results. And if you really want to flex, you could create a bookmarklet that searched Google for items indexed only within a specific date range.
Would you like to see me do another article with more advanced options for these bookmarks? Let me know.
Thanks to John for the interesting and fun search problem!
Categories: Learning Search