Search in sources :

Example 6 with Document

use of com.jsoup.nodes.Document 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);
            }
        }
    };
}
Also used : VolleyError(com.android.volley.VolleyError) HashMap(java.util.HashMap) DBHelper(com.nullsky.fba.DBHelper) StringRequest(com.android.volley.toolbox.StringRequest) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) Document(com.jsoup.nodes.Document) Elements(com.jsoup.select.Elements) SuppressLint(android.annotation.SuppressLint) Response(com.android.volley.Response) RequestQueue(com.android.volley.RequestQueue)

Example 7 with Document

use of com.jsoup.nodes.Document in project User-Behavior-in-Facebook by abozanona.

the class Parser method parseBodyFragment.

/**
 * Parse a fragment of HTML into the {@code body} of a Document.
 *
 * @param bodyHtml fragment of HTML
 * @param baseUri base URI of document (i.e. original fetch location), for resolving relative URLs.
 *
 * @return Document, with empty head, and HTML parsed into body
 */
public static Document parseBodyFragment(String bodyHtml, String baseUri) {
    Document doc = Document.createShell(baseUri);
    Element body = doc.body();
    List<Node> nodeList = parseFragment(bodyHtml, body, baseUri);
    // the node list gets modified when re-parented
    Node[] nodes = nodeList.toArray(new Node[nodeList.size()]);
    for (Node node : nodes) {
        body.appendChild(node);
    }
    return doc;
}
Also used : Element(com.jsoup.nodes.Element) Node(com.jsoup.nodes.Node) Document(com.jsoup.nodes.Document)

Aggregations

Document (com.jsoup.nodes.Document)7 Element (com.jsoup.nodes.Element)3 Elements (com.jsoup.select.Elements)3 Cleaner (com.jsoup.safety.Cleaner)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 RequestQueue (com.android.volley.RequestQueue)1 Response (com.android.volley.Response)1 VolleyError (com.android.volley.VolleyError)1 StringRequest (com.android.volley.toolbox.StringRequest)1 GetHtml (com.fba.GetHtml)1 Node (com.jsoup.nodes.Node)1 DBHelper (com.nullsky.fba.DBHelper)1 HashMap (java.util.HashMap)1 JSONArray (org.json.JSONArray)1