use of com.jsoup.select.Elements in project User-Behavior-in-Facebook by abozanona.
the class ListLinks method main.
public static void main(String[] args) throws IOException {
Validate.isTrue(args.length == 1, "usage: supply url to fetch");
String url = args[0];
print("Fetching %s...", url);
Document doc = Jsoup.connect(url).get();
Elements links = doc.select("a[href]");
Elements media = doc.select("[src]");
Elements imports = doc.select("link[href]");
print("\nMedia: (%d)", media.size());
for (Element src : media) {
if (src.tagName().equals("img"))
print(" * %s: <%s> %sx%s (%s)", src.tagName(), src.attr("abs:src"), src.attr("width"), src.attr("height"), trim(src.attr("alt"), 20));
else
print(" * %s: <%s>", src.tagName(), src.attr("abs:src"));
}
print("\nImports: (%d)", imports.size());
for (Element link : imports) {
print(" * %s <%s> (%s)", link.tagName(), link.attr("abs:href"), link.attr("rel"));
}
print("\nLinks: (%d)", links.size());
for (Element link : links) {
print(" * a: <%s> (%s)", link.attr("abs:href"), trim(link.text(), 35));
}
}
use of com.jsoup.select.Elements in project User-Behavior-in-Facebook by abozanona.
the class Document method normaliseStructure.
// merge multiple <head> or <body> contents into one, delete the remainder, and ensure they are owned by <html>
private void normaliseStructure(String tag, Element htmlEl) {
Elements elements = this.getElementsByTag(tag);
// will always be available as created above if not existent
Element master = elements.first();
if (elements.size() > 1) {
// dupes, move contents to master
List<Node> toMove = new ArrayList<Node>();
for (int i = 1; i < elements.size(); i++) {
Node dupe = elements.get(i);
for (Node node : dupe.childNodes) toMove.add(node);
dupe.remove();
}
for (Node dupe : toMove) master.appendChild(dupe);
}
// ensure parented by <html>
if (!master.parent().equals(htmlEl)) {
// includes remove()
htmlEl.appendChild(master);
}
}
use of com.jsoup.select.Elements in project User-Behavior-in-Facebook by abozanona.
the class Element method getElementById.
/**
* Find an element by ID, including or under this element.
* <p>
* Note that this finds the first matching ID, starting with this element. If you search down from a different
* starting point, it is possible to find a different element by ID. For unique element by ID within a Document,
* use {@link Document#getElementById(String)}
* @param id The ID to search for.
* @return The first matching element by ID, starting with this element, or null if none found.
*/
public Element getElementById(String id) {
Validate.notEmpty(id);
Elements elements = Collector.collect(new Evaluator.Id(id), this);
if (elements.size() > 0)
return elements.get(0);
else
return null;
}
use of com.jsoup.select.Elements in project User-Behavior-in-Facebook by abozanona.
the class MyService method getFilters.
private void getFilters(final CallbackResponce fn) {
String userId = MainActivity.c_user;
String url = "https://mbasic.facebook.com/allactivity/options?id=" + userId;
new GetHtml(url) {
@Override
public void getHtmlListener(String html) {
Document dom0 = Jsoup.parse(html);
Elements dom = dom0.select("li a");
ArrayList<String> log_filters = new ArrayList<>();
for (int i = 1; i < dom.size(); i++) {
String url = dom.get(i).attr("href");
log_filters.add(url.substring(url.lastIndexOf("=") + 1));
}
fn.Callback(log_filters);
}
};
}
use of com.jsoup.select.Elements in project User-Behavior-in-Facebook by abozanona.
the class ActivityLog method getActivityLogData.
private void getActivityLogData(final long date, String log_filter) {
final String userId = getSingleValue.getString("c_user", "");
String url = "https://mbasic.facebook.com/" + userId + "/allactivity?log_filter=" + log_filter;
url = "https://mbasic.facebook.com/" + userId + "/allactivity?log_filter=" + "cluster_11";
Log.d("ActivityLog", url);
new GetHtml(url) {
@Override
public void getHtmlListener(String html) {
final ArrayList<String> links = new ArrayList<>();
Document dom0 = Jsoup.parse(html);
int day = Integer.parseInt((String) DateFormat.format("dd", date));
int month = Integer.parseInt((String) DateFormat.format("MM", date));
int year = Integer.parseInt(((String) DateFormat.format("yyyy", date)).substring(2));
String _day = day + "";
if (day < 10)
_day = "0" + _day;
String _month = month + "";
if (month < 10)
_month = "0" + _month;
String divId = "#tlUnit_" + _month + "_" + _day + "_" + year;
Elements tlUnit = dom0.select(divId);
if (tlUnit == null) {
return;
}
Elements dom = tlUnit.select("a");
for (int i = 0; i < dom.size(); i++) {
if (!dom.get(i).hasAttr("href"))
continue;
String _link = dom.get(i).attr("href");
if (_link != null) {
_link = replaceWithHash(_link);
if (_link.length() != 0) {
links.add(_link);
}
}
}
if (links.size() != 0) {
String url = "https://fba.ppu.edu/submitStudyResults.php";
RequestQueue queue = Volley.newRequestQueue(MainActivity.instance);
StringRequest postRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
new DBHelper(context).setJsonData(links.toString());
Log.d("Response", response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
protected Map<String, String> getParams() {
String uuid = getSingleValue.getString("clientId", "");
if (uuid.equals("")) {
uuid = "mobile" + UUID.randomUUID().toString();
setSingleValue.putString("clientId", uuid);
}
JSONArray arr = new JSONArray();
for (int i = 0; i < links.size(); i++) arr.put(links.get(i));
String clientId = getSingleValue.getString("clientid", "");
if (clientId.equals("")) {
clientId = randomString();
setSingleValue.putString("clientid", clientId);
setSingleValue.apply();
}
Map<String, String> params = new HashMap<>();
params.put("clientId", clientId);
params.put("data", links.toString());
return params;
}
};
queue.add(postRequest);
}
}
};
}
Aggregations