Created
January 24, 2020 16:48
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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