Skip to content

Instantly share code, notes, and snippets.

@jmaccabee
Created January 24, 2020 16:48
Show Gist options
  • Save jmaccabee/2dc47afa15dd13fe0db5323c671f272a to your computer and use it in GitHub Desktop.
Save jmaccabee/2dc47afa15dd13fe0db5323c671f272a to your computer and use it in GitHub Desktop.
A utility function for extracting the JSON blob from Javascript tag text in the DOM.
import json
import re
def extract_json(text):
maybe_match = re.search('({.*:.*})', text)
if maybe_match:
match = maybe_match.groups(1)[0]
return json.loads(match)
return {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment