I’m doing some HTML scraping, and found the info I need as part of some tag in the HTML for the page.
window.__Y_DATA__ = JSON.parse("{ \"__PRELOADED_QUERIES__\": {\"yada yada \":67}}}]]} }");
Using some String.replace, I can clean up the JSON string and Jason.decode!()
runs without raising.
y_data
|> String.replace("window.__Y_DATA__ = JSON.parse(", "")
|> String.replace(");", "")
|> Jason.decode!()
The problem is that Jason.decode!()
is returning a string, and I can’t seem to access any of the properties of the JSON.
y_data_json["__PRELOADED_QUERIES__"]
|> IO.inspect()
The following arguments were given to Access.get/3:
# 1
"{ \"__PRELOADED_QUERIES__\": {\"queries\":[[[\"@web/domain-content/get-page-content\",{\"breadcrumbs\":true,\"children\":true,\"url\":\"/p/-/A-81117190\"}],{\"data\":{\"metadata\":{\"activation_date\":\"2020-12-01T07:00Z\",\"deactivation_date\":\"2030-12-04T08:00Z\",\"seo_data\":{\"ca
# 2
"__PRELOADED_QUERIES__"
# 3
nil
Attempted function clauses (showing 5 out of 5):
def get(%module{} = container, key, default)
def get(map, key, default) when is_map(map)
def get(list, key, default) when is_list(list) and is_atom(key)
def get(list, key, _default) when is_list(list)
def get(nil, _key, default)
Typically Jason.decode!()
has always returned a Map for me, so I appreciate the help!