Banging my head here..
I am trying to parse the html source for the entire contents of javascript variable 'ListData' with regex which starts with the declaration var Listdata = and ends with };.
I found a solution which is similar:
Fetch data of variables inside script tag in Python or Content added from js
But I am unable to get it to match the entire regex.
Code:
# Need the ListData object
pat = re.compile('var ListData = (.*?);')
string = """QuickLaunchMenu == null) QuickLaunchMenu = $create(UI.AspMenu,
null, null, null, $get('QuickLaunchMenu')); } ExecuteOrDelayUntilScriptLoaded(QuickLaunchMenu, 'Core.js');
var ListData = { "Row" :
[{
"ID": "159",
"PermMask": "0x1b03cc312ef",
"FSObjType": "0",
"ContentType": "Item"
};
moretext;
moretext"""
#Returns NoneType instead of match object
print(type(pat.search(string)))
Not sure what is going wrong here. Any help would be appreaciated.
'(?m)var ListData = (.*?)};$''(?sm)var ListData = (.*?)};$'};appears at the end of the line. Is it really like that? The.*?matches any 0+ chars, as few as possible, up to the first};that is at the end of the line. Please add those details to the question as it is an important restriction.