Example usage for org.jsoup.nodes Element getElementsByAttributeValueContaining

List of usage examples for org.jsoup.nodes Element getElementsByAttributeValueContaining

Introduction

In this page you can find the example usage for org.jsoup.nodes Element getElementsByAttributeValueContaining.

Prototype

public Elements getElementsByAttributeValueContaining(String key, String match) 

Source Link

Document

Find elements that have attributes whose value contains the match string.

Usage

From source file:org.loklak.api.search.WeiboUserInfo.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Query post = RemoteAccess.evaluate(request);

    // manage DoS
    if (post.isDoS_blackout()) {
        response.sendError(503, "your request frequency is too high");
        return;// w w w . jav a  2s  .  com
    }

    String url = post.get("url", "");
    JSONObject obj = new JSONObject();
    Document doc = Jsoup.connect(url).get();
    Elements infos;
    infos = doc.getElementsByAttributeValue("class", "li_1 clearfix");

    if (infos != null) {
        Element info;
        String profile;
        for (int i = 0; i < infos.size(); i++) {
            info = infos.get(i);
            if (info.getElementsByAttributeValueContaining("href", "loc=infblog").size() == 0) {
                profile = info.getElementsByAttributeValue("class", "pt_detail").first().text().trim();
                obj.put("pro", profile);
                switch (info.getElementsByAttributeValue("class", "pt_title S_txt2").first().text()) {
                case "Nickname":
                    obj.put("username", profile);
                    break;
                case "Location":
                    obj.put("Address", profile);
                    break;
                case "Gender":
                    obj.put("Gender", profile);
                    break;
                case "??":
                    obj.put("Sexuality", profile.replace("t", "").replace("rn", ""));
                    break;
                case "":
                    obj.put("Relationship", profile.replace("t", "").replace("rn", ""));
                    break;
                case "Birthday":
                    obj.put("Birthday", profile);
                    break;
                case "":
                    obj.put("Blood", profile);
                    break;
                case "Domain Name":
                    if (info.getElementsByAttributeValueContaining("href", "loc=infdomain").size() != 0)
                        profile = info.select("a").text();
                    obj.put("Personaldomain", profile);
                    break;
                case "":
                    obj.put("Profile", profile);
                    break;
                case "Registration":
                    obj.put("Registertime", profile.replace("t", "").replace("rn", ""));
                    break;
                case "Email":
                    obj.put("Email", profile);
                    break;
                case "QQ":
                    obj.put("Qq", profile);
                    break;
                case "":
                    obj.put("College", profile.replace("t", "").replace("rn", ""));
                    break;
                case "Tags":
                    obj.put("Tag", profile.replace("t", "").replace("rn", ""));
                    break;
                }

            } else {
                String blogurl = info.select("a").text();
                obj.put("Blog", blogurl);
            }
        }
    }

    //print JSON 
    response.setCharacterEncoding("UTF-8");
    PrintWriter sos = response.getWriter();
    sos.print(obj.toString(2));
    sos.println();
}