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

  • SEARCH
  • Home
  • 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 8711623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:55:27+00:00 2026-06-13T04:55:27+00:00

I want to extract data from a Web site, using Jsoup. The data are

  • 0

I want to extract data from a Web site, using Jsoup. The data are in a table.

HTML code:

<table><tr><td><a href="......">Pop.Density</a></td>
           <td>123</td></tr></table>

I want to print:

zip code...(taken from a text file): 123

I have the following exception:

Exception in thread "main" java.lang.NullPointerException

Any help would be appreciated. Thank you!

This is my code:

String s = br.readLine();
String str="http://www.bestplaces.net/people/zip-code/illinois/"+s;

org.jsoup.Connection conn = Jsoup.connect(str);
conn.timeout(1800000); 
Document doc = conn.get();

for (Element table : doc.select("table"))
{
    for (Element row : table.select("tr")) 
    {
    Elements tds = row.select("td");
    if (tds.size() > 1)
    {
        Element link = tds.get(0).select("a").first();
        String linkText = link.text();

        if (link.text().contains("Pop.Density"))
            System.out.println(s+","+tds.get(1).text());
        }
    }
}

UPDATE:
If I modify the last if():

if (tds.get(0).select("a").text().contains("Pop.Density"))

I do not have any exceptions, but no output either.

  • 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-13T04:55:29+00:00Added an answer on June 13, 2026 at 4:55 am

    Assuming the shared html is not the real one being used, I think its throwing the exception when first TD doesn’t have <a> tag. I think you need to update

      if (tds.size() > 1) 
    

    as

      if (tds.size() > 1 && tds.get(0).select("a") != null 
                              && tds.get(0).select("a").first() ! null)
    

    If this is not the case, sharing the line number of NullPointerException origin can help better finding the solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want extract the path of images from a html page using PHP-preg_match_all(), the
I am using python's beautiful stone soup to extract data from this web page
Let say I want to extract data from a web page with the following
I'm trying to extract some certain data from a website using JSoup and Java.
I want to create a Silverlight app to extract and manipulate data from an
I have following data in my table. alt text http://img26.imageshack.us/img26/3746/productfield.png I want to extract
HI, I want to extract data from a website but it uses some strange
I am trying to extract data from website using perl API. The process is
I want to extract data from a word document with extension docx. This document
I am trying to extract data from website using Perl API. I am using

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.