I'm trying to scrap something using nokogiri, I want to get the value inside JavaScript array, like the value of 'b' in this code.
<script>
var foo = [bar, [a, b, c , d], value, some value, . . ]
</script>
I got the script block by using doc.search("script")[18].content
, How can I get the value of 'b' here?
You can do this pretty easily:
Testing with a real value:
The downside is it's susceptible to changes in the JavaScript string formatting, which makes it fragile. You get to decide whether you want to go down that path.
Remember, all content in HTML source is a string, so you can tear things up using normal string processing once you've narrowed down what you want to look at.