7

Whenever I type a search query in Google Search, I am presented with long and complicated URLs like this one:

https://www.google.com/#hl=en&tbo=d&output=search&sclient=psy-ab&q=get+google+search+URL&oq=get+google+search+URL&gs_l=hp.3..0i30j0i8i30l5j0i22l2.755.6361.1.6653.36.21.6.6.7.0.450.3055.9j9j1j1j1.21.0.les%3B..0.0...1c.1.QWiPCjGahHw&psj=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&bvm=bv.41642243,d.dmQ&fp=9f9dd1f0efa38569&biw=1366&bih=631

Is there a more concise way to write Google Search URLs, without any unnecessary parameters?

1

3 Answers 3

10

It is possible to generate more concise Google Search URLs, as shown here: https://www.google.com/search?q=%22Stack+Exchange%22+OR+StackOverflow

This URL corresponds to the search query "Stack Exchange" OR StackOverflow. All you need to do is write the search string after https://www.google.com/search?q=., and this will take you to the search results page for that query.

3

TL;DR

  1. 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.
  2. 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,

  1. 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.

  2. Go to Advanced Search.

  3. Craft your search query by filling in the input boxes and selecting values from the dropdowns.

  4. 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=
    
  5. 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.

  1. Open the Console using the keyboard shortcut by clicking the browser menu.
  2. Copy and paste or type one of the above JavaScript statements in the Console.
  3. Press Enter to run it.
  4. The console will write the URL without the empty parameters.
2
  • Thanks. I was wondering how to change the language used in Google webpages? For example, I can't access Google directly, but only indirectly by webtopdf.com. When I performed a Google search by webtopdf.com, the output showed that the language used in Google webpages is Korean, but I wanted English.
    – Tim
    Commented May 20 at 15:48
  • @Tim You are welcome. A follow-up question should be posted as a new question. Commented May 20 at 18:55
1

most simple and short solutions include:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.