Execute a String as a command/Using variables as arguments from Site command

Hi everyone,

I'm currently trying to make a snippet that will allow me to dynamically extract info from different websites inserted within a text form present in the same snippet.

I'm running into a wall whenever I try to get the Site command to extract the info from a variable URL. I've tried passing the variable as an argument for a function or using a variable as an argument for the SITE command however I cannot get this to work; Is this because of the current limitations of text blaze? Or is there a way to get this to work?

{TEST=(x)->{site: text; page=https://legit.website/x ; select=ifneeded; selector=.amount-value}}

This returns the error: No matching tab found for "https://legit.website/x", which makes me think the Site command is trying to look for "https://legit.website/x" instead of "https://legit.website/path321"

I've also tried with

{site: text; page=https://legit.website/{=path}; select=ifneeded; selector=.amount-value}

This returns the error: No matching tab found for "https://legit.website/[Error - This setting doesn't allow commands like "{=path}"]". Making me understand that it is simply not allowing me to use a variable inside of the Site command.

I'm trying to get this to work because I'm using a form to get the URL dynamically

{formtext: name=path}

Any ideas on how to rewrite this code or fixes for my issue will be greatly appreciated!

Hi and welcome to the forum! :slight_smile:

Your interpretation is correct and you have tried the right things. Sadly, the page= setting does not take a variable input, which is why you got that error.

Have you tried this:

{site: text; page=https://legit.website/*; select=ifneeded; selector=.amount-value}

Using the * instead of x, this will get the site data from any page whose URL starts with https://legit.website/. In case only one matching Chrome tab is open, it will directly use the values from it. In case more than one matching Chrome tab is open, you would be able to choose which one you want (in a form window that will automatically open). Would that work for you?

Hi there!

Thx a lot for your reply and for the welcome to the forum! :slight_smile:

I've already tried with the "*" instead of "x" however, for this scenario, I need to call the "function"(big quotes here) several times with different paths for which this would not work out for me.

The {site} command does not support variables in its attributes.

So, you first need to statically declare all the paths you need, like so:

 "val1": catch({site: text; page=https://legit.website/path1/*; select=ifneeded; selector=.amount-value}, "not found"),
 "val2": catch({site: text; page=https://legit.website/path2/*; select=ifneeded; selector=.amount-value}, "not found"),
 "val3": catch({site: text; page=https://legit.website/path3/*; select=ifneeded; selector=.amount-value}, "not found")

and then choose the one you want:

{formmenu: values={=keys(site_data_all)}; name=chosen_key}
Value chosen: {=site_data_all[chosen_key]}

Let me know if it works for you.

Thanks a lot for your response, I'm gonna try it out.

I believe it still doesn't fully resolve my needs, but it does get me a lot closer.

Thanks again!