Java HTML Jsoup Document verifyAdultNotice(Document doc)

Here you can find the source of verifyAdultNotice(Document doc)

Description

verify Adult Notice

License

Open Source License

Declaration

public static Document verifyAdultNotice(Document doc)
            throws IOException 

Method Source Code

//package com.java2s;
/*// ww  w . jav a 2 s  .  com
 * Copyright 2009-2012 TauNova (http://taunova.com). All rights reserved.
 *
 * This file is subject to the terms and conditions defined in
 * file 'LICENSE.txt', which is part of this source code package.
 */

import java.io.IOException;

import java.util.Iterator;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

public class Main {
    private static final String ADULT_NOTICE = "Adult Content Notice";

    public static Document verifyAdultNotice(Document doc)
            throws IOException {
        Document document = doc;

        if (ADULT_NOTICE.equals(doc.title())) {
            Element form = document.select("form[action~=adult_\\w+.bml$]")
                    .first();
            Element hidden = form.select("input[name=ret]").first();
            Element submit = form.select("input[name=adult_check]").first();

            Connection conn = Jsoup.connect(form.attr("action"));

            Iterator<Element> iterator = form.select("input").iterator();
            while (iterator.hasNext()) {
                Element element = iterator.next();
                //System.out.println("   -- " + element.attributes());
                conn = conn.data(element.attr("name"),
                        element.attr("value"));
            }

            document = conn.post();
        }

        return document;
    }
}

Related

  1. postDocument(String url, Collection data)
  2. removeTag(Document doc, String selector)
  3. retrieveHiddenInputs(Document doc)
  4. saveDocumentToDirectory(final org.jsoup.nodes.Document doc, final String fileName, final Path tmpDir)
  5. stripTags(Document document)