How Can I Set KM to Find & Copy a String of Numbers in a Document

OK....

I have a large document (html document from an API call on a google chrome tab) and buried in that document is a string of numbers I want KM to extract.

In fact, it has 151 stings like this one

"asin":"1629375454"

I would like to press a hot key and have KM search & copy all 151 of this particular number string (1629375454).... copy the 10 digit string and paste all 151 strings in a spreadsheet for me.

I am brand new and have no clue how to make this happen.

Any insight??

George

@George, welcome to Keyboard Maestro (KM) and its Forum.
KM is one of the best Mac automation tools available, its Forum is one of the best and friendliest forums on the Internet. Whenever you reach a tough stumbling block trying to use KM, please feel free to post your question/problem here for help.

Now, to your question/request:

I have no doubt KM to easily do this automation for you, as we have done it many times for similar requests.

But, to start with, you need to provides us with more information.
We need real-world examples of:

  • Your source data
    • Be sure to provide enough examples to cover all of the cases (variations) the data might come in.
    • Do NOT "clean up" the data. Give it to us exactly like you will be receiving it for processing.
  • The results you want

Please put both in Forum Code Blocks, using "text" as the language.

Also upload a zip file of the spreadsheet (Excel?) file both BEFORE and AFTER the data is processed.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@George, you will also find this helpful:

Tip: How Do I Get The Best Answer in the Shortest Time?

Getting Started with Keyboard Maestro

For more help, see Getting Started with Keyboard Maestro and the Forum .

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

There are two steps to the process:

  1. Extracting the text from the page
  2. Processing the text.

In all likelihood you can use the Execute a JavaScript in Front Browser action, and return something like document.body.innerText. That will get you all the text in the window (hopefully).

Then you can process the text to find the desired strings. As @JMichaelTX mentions, its not entirely clear. What do you want to find? All the cases of "asin":"DIGITS"? In that case you can use the For Each action together with the Substrings In collection, using a regular expression like:

"asin":"(\d+)"

You will have to repeat the regex with the index variable to extract just the digits using a Search using Regular Expression action.

And then I would simply append them all to a results variable, and eventually set the clipboard to the entire column, which you can then paste in to your spreadsheet.

Hey George,

Welcome to the forum.  :smile:

In a word? No.

Because... Scraping web pages and extracting information requires access to the actual data – or a significantly more detailed explanation of the requirements.

Peter has given you a pretty good starting point, but as a new user that might not make much sense to you.

If not then we need more information to be able to help.

If you can provide the actual web page that would be a good start.

-Chris