TL;DR
- If you need a simple search, use www.google.com/search?q=query, replacing
query
with your search query. When doing this in the address bar, you do not need to worry about replacing spaces with other characters.
- If your query includes symbols like +, [,], #, ?, among others, or your URL should be a complex search, get the Google Search URL from Advanced Search using it in private / safe / incognito mode to avoid having to deal with extensions and third-party tools.
The URL is polluted by navigating from one place to another; it is possible if the user is signed in one or multiple accounts with active browser extensions, among other factors.
Each navigation step might add a parameter to the URL that tells the client-side code something that might be needed to make certain features work; some are related to helping the developers learn about the user navigation journey. Instead of grabbing that URL,
Open your web browser in private mode. In Chrome, this mode is called incognito mode; other web browsers have other names, like Private, Safe, etc.
Ensure no extensions are enabled, as they might add unnecessary parameters; otherwise, disable them.
Go to Advanced Search.
Craft your search query by filling in the input boxes and selecting values from the dropdowns.
Click the button Advanced Search.
https://www.google.com/search?as_q=sun&as_epq=&as_oq=&as_eq=computers&as_nlo=&as_nhi=&lr=lang_en&cr=countryUS&as_qdr=y&as_sitesearch=&as_occt=any&as_filetype=&tbs=
You might remove any parameters with no value, then copy the URL from the address bar.
In the above example, the parameters with no value are the following:
- &as_epq=
- &as_oq=
- &as_nlo=
- &as_nhi=
- &as_sitesearch=
- &as_filetype=
- &tbs=
These parameters correspond to empty Advanced Search inputs. The empty parameters might be removed manually or with the help of some end-user tooling, spreadsheet formulas, scripts, etc.
Using JavaScript and the Web Browser Console
Removing the empty parameters could be done by running a one-line JavaScript code in the JavaScript console of your web browser. If you have used the Advanced Search as explained in the above section, you might use the following:
window.location.href.replace(/(&[a-z_]+=)(?=&|$)/g,"")
The above code uses window.location.href
method to take the URL from the address bar and then the String.prototype.replace
method and the regular expression /(&[a-z_]+=)(?=&|$)/g
to remove the parameters with no values.
If you have got the URL by other means, use
"PUT HERE YOUR URL".replace(/(&[a-z_]+=)(?=&|$)/g,"")
Keyboard shortcuts for Chrome to open the console:
- Windows: Ctrl + Shift + J.
- Mac: Cmd + Opt + J.
NOTE: Do not copy code found on random web pages and paste it to the web browser console if you don't understand what the code does.
- Open the Console using the keyboard shortcut by clicking the browser menu.
- Copy and paste or type one of the above JavaScript statements in the Console.
- Press Enter to run it.
- The console will write the URL without the empty parameters.