Java.net.SocketTimeoutException: Read error while trying to read from table

I am working on coding a program that will go and get the price of a person from a table on a website. The code gets the last name and looks for a table for that name before returning the price (another column) whenever I run it. I get java.net.SocketTimeoutException: timeout

This is the code I use to request a website

public String price(String lastName) throws IOException
{
    Document doc = Jsoup.connect(url).get();

    Elements rows = doc.getElementsByTag("tr");;

    for(Element row : rows)
    {
        Elements columns = row.getElementsByTag("td");
        String lastName = columns.get(0).text();
        String price = columns.get(2).text();
        if(lastName.equalsIgnoreCase(name))
        {
            return price;
        }
    }
    return null;
}
+4
source share
1 answer

Try the following:

Jsoup.connect(url).timeout(60*1000).get(); 

or...

Jsoup.connect(url).timeout(0).get();
+9
source

Source: https://habr.com/ru/post/1531460/


All Articles