I'm scraping a web page using casperjs, it works great with global JavaScript values, but now I'm stuck at getting out variables form a jQuery closure like this:
$(document).ready(function(){
var storeData = {
lon: "-5.91829",
lat: "54.65583",
name: "John Smith"
};
SOMEGLOBALVAR.storeFinder.addStore(storeData);
});
I can't find a way to to get my hands on lon, lat and name!
So I decided to select the script tag, then use regex to get out the code out of the script tag. Here's my ugly regex I built using an online editor:
/var storeData = {\n\t*id.*,\n\t.*(\n\t)*\n\t*.*\n\t*.*\n\t*[a-zA-Z: 0- 9,"]*\n\t*[a-zA-Z: 0-9,"]*\n\t*[a-zA-Z: 0-9,"]*\n\t*\};/g
So my question has two parts:
is there a way to access the lon, lat and name inside that function? (I'm scraping so I can't change the function itself)
How can I make my regex better?