Copy Company Name and Link from Search Results on


What I am trying to do, is (on paper) very straight forward, however, my lack of programming knowledge might be keeping me from saving plenty of hours of manual work a week. I'd be super-grateful if you guys could help out with this.

On this page you will see a set of results, these are all (or mostly) suppliers of baseball bats.

All I am trying to do is to automate the right-clicking on the company name of each result on the page (even if if the same company shows twice or the result might not be relevant) and copying that link.

The part I do not manage to figure out on my own is how to identify the company link to right-click. The CENTRAL PART of the company URL seems to be always the same, that should help to identify the URL in the page:


Just to give you some additional background:
These links will be copy/pasted in a Google Sheet, the automation will go through all of the results in the page and also run through all of the pages, there can be sometimes 100+ pages of results.

At the moment I am just looking for the code that will help me identify the company link to right-click, I think I will be able to do set-up all the rest.

I am on Keyboard Maestro 9.0.6 on macOS 10.15.7


Anyone any idea? Can this be solved with Java? I was thinking maybe I can get a Java developer on Fiverr helping out with the coding?

so, you just need to extract the URLs, correct?

applying regex to the source code can help:

OK, assuming that you would like to set the System Clipboard to a list of tab-delimited items, Item Name TAB URL, here is a simple Macro.

How to Use

  1. Open a web page to the search results on
  2. Trigger this Macro
    • It will put the data on the Clipboard
  3. Switch to a Spreadsheet
  4. Paste
    • That will put the data in two columns:
      • Item Name
      • Item URL

Here's the JavaScript:

var itemColl = document.querySelectorAll('a.elements-title-normal');
var linkListStr = Array.from(itemColl).map(function(x) {return x.title + '\t' + x.href;});

Let us know if this works for you.


Hello @JMichaelTX, thanks a lot for helping out with this. When I try to execute the macro on a search result page on it seems is not copying the results on the clipboard.

Here a screenshot of what I've set-up in KM, it should be the same as your example, when checking the clipboard seems that nothing is copied there.

Am I missing something?

Hi there, you lost me @hello. Not sure where to start from with the tip above.. sorry!

does it work on the web page you used in your OP:

If it works there, but not on other pages, try changing this option in the Gear Menu to output any error messages:


The link you provided above in this post doesn't seem to be a Search Results page.

Not sure where to start from with the tip above

you apply it to the source code (Develop > Show Page Source), but follow JTMichael advice, easier to use.

@goat, troubleshooting question: did you enable Javascript in your browser?

Chrome Menu Bar > Develop > Allow JavaScript from Apple Events

1 Like

Hi both,

Thanks a lot for helping me to troubleshoot.

Yes, javascript is enabled I am on Chrome and just double-checked.

I've enabled also the "Include Errors" option but same behaviour. Nothing gets copied in the Clipboard.

This is the page I am testing on

that page works fine for me.
I changed the ouput of the Execute JavaScript to "Display results in window", and I get this:

Please make sure that both the Macro, and the Macro Group it is in are enabled, and that the MG is activated. Set the MG to "always activated" to make sure.

Thank you @JMichaelTX for your continued support. I appreciate that a lot!

I can confirm the macro group and the macro are activated. I have realised that KM throws this error message (I was on "do not disturb" in the previous tests and would not see the notification :blush:).
I wasn't able to expand/read the full message... not sure if I am being very lame...
Bildschirmfoto 2020-11-12 um 09.52.55

I tried also to deactivate any extension in Chrome and compared the code you provided with what I have pasted. No luck.

Now the good news :slight_smile: , it did work on Safari!

So the issue should be related to (my?) Chrome (set-up?) somehow. I've checked and JS is active on my Chrome and I am on the newest version. I am now going to work on this through Safari, more than happy with that for sure! Just wanted to mention that as it might help someone else.

Just one last question, can we change the script so that it pulls the company name and URL instead of the title of the page?

See screenshot below. Right now is pulling the information marked in red. I'd like to pull instead the information marked in green.

You have no idea how much time this will save me, I am so thankful for your help :pray:

Just to add, I am presuming I simply need to change the title style name in the code to consistently pull the company info instead of the specific product. But have no idea how to identify the correct name and correct the code accordingly :frowning:

Hey @goat,

It looks to me like you want something of this nature:

var itemColl = document.querySelectorAll('a.fc3.fs12');
var linkListStr = Array.from(itemColl).map(function(x) {return x.title + '\t' + x.href;});

This works fine for me in both Safari and Chrome on macOS Sierra.


1 Like


This is the best forum in the planet.

Thanks a million @ccstone!


2nd best forum.
I'd tell you about 1st, but 1st rule of 1st one is not to tell about it