Java Code Examples for org.jsoup.parser.Parser#htmlParser()

The following examples show how to use org.jsoup.parser.Parser#htmlParser() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectorTest.java    From jsoup-learning with MIT License 6 votes vote down vote up
public static void main(String[] args) {
    String html = "<body>\n" +
            " <textarea>\n" +
            "        &lt;!-- Text --&gt;\n" +
            "        xxx\n" +
            "    </textarea> \n" +
            " <div> \n" +
            "  <table> \n" +
            "   <!-- InTable --> \n" +
            "   <!-- InTableText --> xxx \n" +
            "   <tbody> \n" +
            "    <tr> \n" +
            "     <!-- InRow --> \n" +
            "     <td> \n" +
            "      <!-- InCell --> </td> \n" +
            "    </tr> \n" +
            "   </tbody> \n" +
            "  </table> \n" +
            " </div> \n" +
            "</body>";
    Parser parser = Parser.htmlParser();
    Document document = parser.parseInput(html, "");
    Elements select = document.select("body div");
    System.out.println(select);
}
 
Example 2
Source File: HttpConnection.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private Request() {
    timeoutMilliseconds = 3000;
    maxBodySizeBytes = 1024 * 1024; // 1MB
    followRedirects = true;
    data = new ArrayList<Connection.KeyVal>();
    method = Method.GET;
    headers.put("Accept-Encoding", "gzip");
    parser = Parser.htmlParser();
}
 
Example 3
Source File: HttpConnection.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
Request() {
    timeoutMilliseconds = 30000; // 30 seconds
    maxBodySizeBytes = 1024 * 1024; // 1MB
    followRedirects = true;
    data = new ArrayList<>();
    method = Method.GET;
    addHeader("Accept-Encoding", "gzip");
    addHeader(USER_AGENT, DEFAULT_UA);
    parser = Parser.htmlParser();
}
 
Example 4
Source File: HttpConnection.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
Request() {
    timeoutMilliseconds = 30000; // 30 seconds
    maxBodySizeBytes = 1024 * 1024; // 1MB
    followRedirects = true;
    data = new ArrayList<>();
    method = Method.GET;
    addHeader("Accept-Encoding", "gzip");
    addHeader(USER_AGENT, DEFAULT_UA);
    parser = Parser.htmlParser();
}
 
Example 5
Source File: HttpConnection.java    From jsoup-learning with MIT License 5 votes vote down vote up
private Request() {
    timeoutMilliseconds = 3000;
    maxBodySizeBytes = 1024 * 1024; // 1MB
    followRedirects = true;
    data = new ArrayList<Connection.KeyVal>();
    method = Connection.Method.GET;
    headers.put("Accept-Encoding", "gzip");
    parser = Parser.htmlParser();
}
 
Example 6
Source File: ParserCorrectorTest.java    From jsoup-learning with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    String htmlWithDivUnclosed = "<body>\n" +
            " <textarea>\n" +
            "        &lt;!-- Text --&gt;\n" +
            "        xxx\n" +
            "    </textarea> \n" +
            " <div> \n" +
            " <div>\n" +
            "  <table> \n" +
            "   <!-- InTable --> \n" +
            "   <!-- InTableText --> xxx \n" +
            "   <tbody> \n" +
            "    <tr> \n" +
            "     <!-- InRow --> \n" +
            "     <td> \n" +
            "      <!-- InCell --> </td> \n" +
            "    </tr> \n" +
            "   </tbody> \n" +
            "  </table> \n" +
            " </div> \n" +
            "</body>";
    Parser parser = Parser.htmlParser();
    parser.setTrackErrors(100);
    Document document = parser.parseInput(htmlWithDivUnclosed, "");
    List<ParseError> errors = parser.getErrors();
    System.out.println(errors);

}
 
Example 7
Source File: PageErrorChecker.java    From jsoup-learning with MIT License 5 votes vote down vote up
public static List<ParseError> check(String url) throws IOException {
    Parser parser = Parser.htmlParser();
    parser.setTrackErrors(100);
    String body = Jsoup.connect(url).userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36")
            .execute().body();
    parser.parseInput(body, url);
    List<ParseError> errors = parser.getErrors();
    return errors;
}
 
Example 8
Source File: SelectorExtractor.java    From web-data-extractor with Apache License 2.0 2 votes vote down vote up
/**
 * change parser to htmlParser.
 *
 * @return
 */
public SelectorExtractor htmlParser() {
    this.parser = Parser.htmlParser();
    return this;
}