Skip to content

Commit

Permalink
Attempt to extract JSON from the hopefully HTML profile we got
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeusz “tadzik” Sośnierz committed Apr 24, 2016
1 parent 826bf67 commit 5980f65
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions main.cpp
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5980f65

Please sign in to comment.