List of usage examples for org.jsoup.safety Whitelist addAttributes
public Whitelist addAttributes(String tag, String... attributes)
From source file:net.duckling.falcon.xss.JSONConfig.java
private static void addTags(Whitelist whitelist, JSONObject config) { JSONObject whiteListJson = (JSONObject) config.get("whiteList"); for (String tagname : whiteListJson.keySet()) { whitelist.addTags(tagname);//from ww w .j av a 2 s .c om JSONArray attributes = (JSONArray) whiteListJson.get(tagname); for (Object attribute : attributes) { whitelist.addAttributes(tagname, (String) attribute); } } }
From source file:com.elevenpaths.googleindexretriever.GoogleSearch.java
/** * Make the query to google and return the data. * * @param query/* ww w . j a va 2s .c o m*/ * textfield for google * @return webpage in Document format */ private Document getData(String query) throws CaptchaException, EmptyQueryException, UnsupportedEncodingException { if (this.query.isEmpty() || this.query == null) { throw new EmptyQueryException(); } Connection conn = null; Document doc = null; String request = "https://www.google.com/search?q=" + URLEncoder.encode(stripXSS(query), "UTF-8"); if (!tokenCookie.isEmpty()) { request = request + "&google_abuse=" + URLEncoder.encode(tokenCookie, "UTF-8"); } try { conn = Jsoup.connect(request).method(Method.GET) .userAgent("Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/48.0") .header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") .header("Cookie", tokenCookie).header("Connection", "keep-alive").ignoreHttpErrors(true) .timeout(5000); if (!referer.isEmpty()) { conn.header("Referer", referer); } Connection.Response response = conn.execute(); if (response.statusCode() == 503) { referer = response.url().toString(); idCaptcha = getIDCaptcha(response.parse()); getCaptcha("https://ipv4.google.com/sorry/image?id=" + idCaptcha + "&hl=es&" + referer.substring(referer.indexOf('?') + 1)); throw new CaptchaException(); } doc = Jsoup.parse(response.body()); // Clean the response Whitelist wl = new Whitelist().basic(); wl.addAttributes("span", "class"); Cleaner clean = new Cleaner(wl); doc = clean.clean(doc); } catch (IOException e) { //System.out.println(e.getMessage()); e.printStackTrace(); } return doc; }