Extracting a JS variable

I suspect I'm going about an easy process in the most difficult manner possible.

The head section of the target site has a JavaScript script which contains many variables. I need to extract one of those variables.

So if I have:

<script type="text/javascript">
    window.site_vars = {"width": "100", "actions": "r=x100&c=80x80", "height": "80"}
    </script>

How would I return the value of "height"? Anything I try is choking on the quotation marks.

Can you provide the URL with the script?

On www.thetowntalk.com, I'd like to have "Alexandria, LA" returned. This is the value of the script variable "STATION_CITY_STATE".

You can use the following regex:
=RegexpFindOnUrl(A1;"""STATION_CITY_STATE"":\s""([a-zA-Z0-9\s,]*)"",";1)

2 Likes

Excel doesn't care for that initially. Couple tweaks and it worked just great! Needed to switch out the semicolons for commas.

=RegexpFindOnUrl(A30,"""STATION_CITY_STATE"":\s""([a-zA-Z0-9\s,]*)"",",1)

Yes, my formula is in european formula syntax :slight_smile: