inpX
: must be a bs4 document/tag/ResultSet or a string or a list of strings- ( target variable must be JSON and seaparated from other variables by
;
)
- ( target variable must be JSON and seaparated from other variables by
varName
: name of the target variable- ( only the first variable found with the specified name will be returned )
selector
: a CSS selector for searching the bs4 document/tag for target script- ( if inpX is a script-tag/ResultSet/string/list then selector doesn't matter )
prepFn
: should be a univariate function that takes a string and returns a string- ( for modifying the script string before searching for and parsing variable )
jsonload_from_script(BeautifulSoup('<script>y=8</script>'), 'y')
-->8
jsonload_from_script(['y=8','x=7'], 'x')
-->7
jsonload_from_script('y=8;x=7', 'x')
-->7
jsonload_from_script('y=8;x={"a":1};w="lorem";', 'x')
-->{'a':1}
jsonload_from_script('y=8;x={"a":1};w="lorem";', 'w')
-->'lorem'