Have you ever tried to copy the links that are listed in your Google search results? I bet most of us don’t do it. We usually navigate to the page and if we find it interesting then we either copy the URL or just bookmark it.

But, if there is a need where in you just have to just copy the URLs from the Google search results then you would be surprised to see the link you get. When you mouse hover on the search results you can see the direct website URL but when you right click on the link and click Copy the link address you won’t get a direct URL.

Google Search Result Indirection

For example, when I search for articpost on Google and copy the articpost website listed on the search result I get the below link:

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&ved=0CCoQFjAB&url=http%3A%2F%2Fwww.articpost.com%2F&ei=CDLxUq9hzfqJB5nSgcgE&usg=AFQjCNGAsI7hnWU5pKH00ZJ6v0XsybM7eQ

But all you need is just http://www.articpost.com/ so how to make the links in the search results easier to copy? We can follow any of the below methods to turn off Google search results indirection.

Chrome Extension

Add the Don’t track me Google Chrome extension that will turn off Google search results indirection. Just add this to your Chrome browser and all your Google search results should now have the direct URL.

Firefox Extension

Add the Google/Yandex search link fix Firefox extension that will fix the Google Search results indirection. This extension also fixes URLs in Yandex Search Engine too.

Use Developer Tools

  • Go to www.google.com
  • Launch developer tools in Chrome, Firefox or Internet Explorer. F12 is the common shortcut key to launch developer tools in all the three browsers.
  • Go to the Console tab, copy and paste the below code in the script execution space and press enter.
    javascript:function rwt(a,g,h,n,o,i,c,p,j,d){return a};
  • Now search for your query in Google and try to copy the link address. You should now get the actual URL.
RWT function execution

RWT function execution

If you are wondering from where I got the above rwt function, right click on the Google page and click View Page Source (in Internet Explorer it’s just View Source).Now search for rwt and you should see the function. This is the function that the Google page uses to redirect you to the website.

Using JavaScript

If you look into the below URL closely you can see that there is a URL in the link (we call it query string)

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&ved=0CCoQFjAB&url=http%3A%2F%2Fwww.articpost.com%2F&ei=CDLxUq9hzfqJB5nSgcgE&usg=AFQjCNGAsI7hnWU5pKH00ZJ6v0XsybM7eQ

So in order to extract the actual URL alone from the above one we can use the match and unescape functions of the JavaScript. Let’s see how to do it:

  • Open Developer Tools in your browser.
  • Copy the lengthy URL from Google search results and assign it to a variable as shown below:

var a=”http://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&frm=1&source=web&cd=2&cad=rja&ved=0CCwQFjAB&url=http%3A%2F%2Fwww.articpost.com%2F&ei=yDLxUo7CEqWViQfHz4HgAg&usg=AFQjCNGAsI7hnWU5pKH00ZJ6v0XsybM7eQ&bvm=bv.60444564,d.aGc”;

  • Now we need to find &url and extract its value, so we will make use of match function,

a.match(“url=([^&]*)”)[1];

Note: The string inside the match function is called regular expression which is used to identify a pattern in any given string.

  • The above script will give you “http%3A%2F%2Fwww.articpost.com%2F” as output.
  • Now to replace the escape sequences in the above URL use the below script,

unescape (“http%3A%2F%2Fwww.articpost.com%2F”);

  • Or you can simply combine the match and unescape into a single query as shown below,

unescape (a.match(“url=([^&]*)”)[1]);

match-unescape-javascript

JavaScript Execution in Firefox

Got a better way of doing this? Share it with us.