I’m trying the extract the ProductValue from the following bit of Javascript:
<script language="javascript" type="text/javascript">
lpAddVars('page','Section','womens');
lpAddVars('page','CartTotal','0.00');
lpAddVars('page','ProductID','43577');
lpAddVars('page','ProductValue','128.00');
</script>
I don’t think Beautiful Soup parses javascript so I think the best way to do this may be to use a regular expression, but I’m very new to re and so far nothing I’ve tried seems to work. Any advice or help on how to accomplish this?
Thanks!
This should work:
So what is “ProductValue.*,’|\”[‘|\”]” even doing?
“ProductValue.*,’|\”[‘|\”]”
ProductValue — just a literal string that you’re searching for
.* — we want any amount of characters, so spaces, single quotes, whatever
, — we’ll stop allowing “.*” to match on all characters once we reach the “,”
[‘|\”] — we want to match either a single quote or a double quote
(.*) — this is the bit we’re actually interested in, which can be any characters
[‘|\”] — again, we’ll stop the “.*” once we reach a closing single or double quote
From this point on, I would do something like: