I'm trying to import all the tables on a website, this one in particular:
For local files that are already tabular, Import[#, "Table"]
works well, but I can't seem to easily import simple tables embbeded in a sites.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI'm trying to import all the tables on a website, this one in particular:
For local files that are already tabular, Import[#, "Table"]
works well, but I can't seem to easily import simple tables embbeded in a sites.
This is only a partial answer because it turns out the AWS JSON is surprisingly complicated. Anyways this might help you get there eventually. Lots of work left unfortunately.
str = Import["http://a0.awsstatic.com/pricing/1/ec2/linux-od.min.js", "String"];
pos = StringPosition[str, "callback"];
obj = StringTake[str, {pos[[1, 2]] + 2, StringLength[str] - 2}];
json = StringReplace[obj, ":" -> "->"];
json = StringReplace[json, "{" -> "<|"];
json = StringReplace[json, "}" -> "|>"];
json = StringReplace[json, "[" -> "{"];
json = StringReplace[json, "]" -> "}"];
json = ToExpression[json];
Now we have an association. We can now access the data in a hierarchical manner e.g.
json[config][regions][[1]][instanceTypes][[1]][sizes][[1]]
which gives us the result:
<|size -> "t2.micro", vCPU -> "1", ECU -> "variable",
memoryGiB -> "1", storageGB -> "ebsonly",
valueColumns -> {<|name -> "linux", prices -> <|USD -> "0.013"|>|>}|>