From 5980f657b0e613269d97334eea723933e2ae611b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadeusz=20=E2=80=9Ctadzik=E2=80=9D=20So=C5=9Bnierz?= Date: Sun, 24 Apr 2016 17:12:17 +0200 Subject: [PATCH] Attempt to extract JSON from the hopefully HTML profile we got --- main.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/main.cpp b/main.cpp index 4f70709..cb2ca62 100644 --- a/main.cpp +++ b/main.cpp @@ -25,6 +25,24 @@ int main(int argc, char *argv[]) QJsonDocument rawdata(QJsonDocument::fromJson(jsondata)); if (!rawdata.isArray()) { + // perhaps we got .html in, let's try to rip JSON from that + QByteArray pattern("var rawData = JSON.parse('"); + int lineStart = jsondata.indexOf(pattern); + if (lineStart != -1) { + int lineEnd = jsondata.indexOf("\n", lineStart); + if (lineEnd != -1) { + // get the actual positions of the JSON string + lineStart += pattern.length(); + lineEnd -= 3; + // cut the excess HTML on both sides + jsondata.truncate(lineEnd); + jsondata = jsondata.mid(lineStart); + } + } + } + rawdata = QJsonDocument::fromJson(jsondata); + if (!rawdata.isArray()) { + // if that didn't work either, we're screwed qDebug() << "Malformed input file"; return 1; }