My goal is to convert a string into a dictionary. Here’s how it looks like:
[exploit] => 1
[hits] => 1
[completed] => 1
[is_malware] => 1
[summary] => 26.0@13965: suspicious.warning: object contains JavaScript
76.0@14467: suspicious.obfuscation using eval
76.0@14467: suspicious.obfuscation using String.fromCharCode
[severity] => 4
[engine] => 60
So I’ve tried several ways to do this, first attempt was to split at \n, but I encountered the problem that for [summary], the contents are split so that didn’t work. Then my second attempt was split at => however I encountered the problem that once I split at => it won’t know that it has to split at \n for the next key. Essentially it should look like this in the end
{ exploit:1, hits:1, completed:1….} so on so forth
Any help would be greatly appreciated.
You can use
re.findallto parse the text:You can put these values into a dictionary by calling
dict.