Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9079589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:52:16+00:00 2026-06-16T19:52:16+00:00

I would like to make a program that parses the html page and selects

  • 0

I would like to make a program that parses the html page and selects useful information and displays it. I did it by opening a stream and then line by line searching for this appropriate content, but this is a time consuming process. So then I decided to do it by treating it as a xml and then using xpath. This I did by making a xml file on my system and loading the contents from the stream, and I got white space error, then I decide to direct open document as

doc = (Document) builder.parse(inputStream);

but the same error still persists. After asking here I was suggested to use jSoup for html parsing, now when I execute my code for:

Document doc= Jsoup.connect(url).get();

I get Read timed out. The same program when made in python and using a naive strategy like using find method of string and searching, I am displayed the contents and that too fast. How to make it work fast in java?

Complete code:

import java.io.*;
import org.jsoup.Jsoup;
import org.jsoup.helper.Validate;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Parser {
public static void main(String[] args) {
    Validate.isTrue(true, "usage: supply url to fetch");
    try{
        String url="http://www.spoj.com/ranks/PRIME1/";
        Document doc= Jsoup.connect(url).get();
        Elements es=doc.getElementsByAttributeValue("class","lightrow");
        System.out.println(es.get(0).child(0).text());


    }catch(Exception e){e.printStackTrace();}
}

}

Exception:

java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:412)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:393)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:159)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:148)
at Parser.main(Parser.java:12)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:52:17+00:00Added an answer on June 16, 2026 at 7:52 pm

    Does your firewall or OS block your request (maybe it blocks java access to internet)? Are you using PC or eg. Android? And is your HTML page a website or a (local) HTML file?
    Please post some more code or the exception you get.

    Please make shure you dont use a DOM Document but org.jsoup.nodes.Document.

    I am displayed the contents

    How do you want to display the content? If you simply need a value like this:

    ...
    <div>some value</div>
    ...
    

    You can do this with jsoup:

    Document doc = ... // parse html file or connect to website
    
    final String value = doc.select("div").first().text();
    
    System.out.println(value);
    

    Edit:

    Since the default connection timeout is 3 sec (3000 millis) it should be changed for big websites, because loading the data may take some time:

    final String url = "http://www.spoj.com/ranks/PRIME1/";
    final int timeout = 4000; // or higher
    
    Document doc = Jsoup.connect(url).timeout(4000).get();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to make a file that only my program has permissions to
I would like to make a program that can process audio. How get an
I would like to make a program that takes input as a string like
I would like to make a program to capture video. What is the best
I would like to make an small program in Windows to duplicate an android
Would like to make anapplication in Java that will not automatically parse parameters used
I would like to make an HTTP/S proxy program to filter/deny certain http traffic
I would like to make my program convert str s into int s in
I have a program that has a MDI host and I would like to
I would like to make a system call to a Linux program from my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.