if (statusCode != 200) {
throw new RuntimeException("Failed to get page: " + statusCode);
}
String response = method.getResponseBodyAsString();
HtmlCleaner html = new HtmlCleaner();
TagNode content = html.clean(response).findElementByAttValue("id", "content", true, false);
Object[] rows = content.evaluateXPath("table/tbody/tr[@id]");
for (Object row: rows) {
if (!(row instanceof TagNode)) {
continue;
}
TagNode rowNode = (TagNode) row;
try {
String s;
Script script = new Script();
String id = rowNode.getAttributeByName("id").replace("scripts-", "");
TagNode nameNode = rowNode.getChildTags()[0].getChildTags()[0];
String scriptUrl = nameNode.getAttributeByName("href");
String description = getText(rowNode, "td[1]/p");
s = getText(rowNode, "td[2]/a");
int reviews = s == null ? 0 : Integer.parseInt(s.replaceAll("\\D", ""));
s = getText(rowNode, "td[2]/span/span[@class='number']");
int averageReview = s == null ? 0 : (int) (Float.parseFloat(s) * 1000);
int posts = Integer.parseInt(rowNode.getChildTags()[2].getText().toString());
int fans = Integer.parseInt(rowNode.getChildTags()[3].getText().toString());
int installs = Integer.parseInt(rowNode.getChildTags()[4].getText().toString());
TagNode updatedNode = rowNode.getChildTags()[5];
String dateString = updatedNode.getChildTags()[0].getAttributeByName("title").replace("Z", "-0000");
script.id = id;
script.url = scriptUrl;
script.updated = sdf.parse(dateString).getTime();
script.installs = installs;