Get a value after a certain text in http

I want to extract the variable value after text "stock price today is " (in this example 239.00) from the output. what is the best way to achieve this?

image

Hello! Welcome to the Make Community!

Can you first try to activate “Parse response” in your HTTP module, and run again?

You should get a parsed version of the output that will be easier to map.
Then, you will normally get a field called: mainEntity that contains a collection in which you have “text” that contains your text.
You could then try to parse this field with a regular expression, using the Text Parser

But first, can you try and see if the output of the HTML can be parsed?

Benjamin

Hi @Gustaf

You can use the following regex expression in “text parser” module to match patterns from the text given:

stock price today is (\d+\.\d+)

Output:


Best regards,

Msquare Automation
Gold Partner of Make
@Msquare_Automation

Welcome to the Make community!

You can use a Text Parser “Match Pattern” module with this Pattern (regular expression):

stock price today is (?<price>\d+\.\d+)

Proof https://regex101.com/r/0n4HgB/1

Important Info

  • :warning: Global match must be set to NO!

Screenshot

Output

Screenshot_2024-10-07_151007


For more information, see Text Parser in the Make Help Center:

Match Pattern
The Match pattern module enables you to find and extract string elements matching a search pattern from a given text. The search pattern is a regular expression (aka regex or regexp), which is a sequence of characters in which each character is either a metacharacter, having a special meaning, or a regular character that has a literal meaning.

Module Export - quick import into your scenario

You can copy and paste this module export into your scenario. This will import the modules (with fields/settings/filters) shown in my screenshots above.

  1. Move your mouse over the line of code below. Copy the JSON by clicking the copy button on the right of the code, which looks like this:

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the editor.

  3. Click on each imported module and re-save it for validation. There may be some errors prompting you to remap some variables and connections.

JSON module export — paste this directly in your scenario

{"subflows":[{"flow":[{"id":225,"module":"http:ActionSendData","version":3,"parameters":{"handleErrors":true,"useNewZLibDeCompress":true},"mapper":{"url":"https://www.investing.com/equities/spiltan-investment-ab","serializeUrl":false,"method":"get","headers":[],"qs":[],"bodyType":"","parseResponse":false,"authUser":"","authPass":"","timeout":"","shareCookies":false,"ca":"","rejectUnauthorized":true,"followRedirect":true,"useQuerystring":false,"gzip":true,"useMtls":false,"followAllRedirects":false},"metadata":{"designer":{"x":1418,"y":-1365},"parameters":[{"name":"handleErrors","type":"boolean","label":"Evaluate all states as errors (except for 2xx and 3xx )","required":true},{"name":"useNewZLibDeCompress","type":"hidden"}]}},{"id":227,"module":"regexp:Parser","version":1,"parameters":{"pattern":"stock price today is (?<price>\\d+\\.\\d+)","global":false,"sensitive":true,"multiline":false,"singleline":false,"continueWhenNoRes":false},"mapper":{"text":"{{225.data}}"},"metadata":{"designer":{"x":1718,"y":-1365},"parameters":[{"name":"pattern","type":"text","label":"Pattern","required":true},{"name":"global","type":"boolean","label":"Global match","required":true},{"name":"sensitive","type":"boolean","label":"Case sensitive","required":true},{"name":"multiline","type":"boolean","label":"Multiline","required":true},{"name":"singleline","type":"boolean","label":"Singleline","required":true},{"name":"continueWhenNoRes","type":"boolean","label":"Continue the execution of the route even if the module finds no matches","required":true}]}}]}],"metadata":{"version":1}}

Note: Did you know you can reduce the size of blueprints and module export code like the above, using the Make Blueprint Scrubber?

Hope this helps! Let me know if there are any further questions or issues.

@samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

Thanks all for the responses. Also, I note that when getting all info based on the URL in the HTTP module it is a lot of data even though what I am seeking (the stock price) is a very small part of the data. Is it possible to delimit Output in HTTP module? for example (see HTTP screenshot above): output should only be Answer to Question: “What is the Spiltan Investment AB Stock price today?”