I'm writing a test code in Ruby and trying to parse a HTML source file of a website. It has a JavaScript variable which I can use to compare it against other values. For example:
<script type="text/javascript" language="JavaScript">
function GetParam(name) {
var req_var = {
a: 'xyz',
b: 'yy.com',
c: 'en',
d:0,
e: 'y'
};
}
</script>
Here I want to extract the variable req_var
from this function. Is it possible to do that? If so can anyone please help me with that?
javascript parser in ruby
rkelly gem threw an exception for me, so I used the fork rkelly-remix -- you have to uninstall the original one because they use the same name:
I had the following JS code:
And this is the code I had to write to parse it:
That results in:
You could use a regular expression to parse it out like this: