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 6338473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:27:09+00:00 2026-05-24T19:27:09+00:00

i am building up a java application to extract the values inside the table

  • 0

i am building up a java application to extract the values inside the table tags using xpath.

Please suggest me an efficient way to get all 200 values from the page. my code works perfectly fine for the 100 rows withing the 1st DataTable. However, i have no way to get to the 2nd dataTable.

i am able to extract them using the following java class.

the expected output

http://a.com/   data for a  526735  Z
http://b.com/   data for b  522273  Z
.
.
.
.

http://c.com/   data for c  578335  Z  
http://d.com/   data for d  513445  Z

<table>
<tbody>
 <tr>
 <td style="padding-right>
 <table class = dataTabe>
  <tbody>
   <tr>
    <td><a HREF="http://a.com/" target="_parent">data for a</a></td>
    <td class="numericalColumn">526735</td>
    <td class="numericalColumn">Z</td></tr>
   <tr>
    <td><a HREF="http://b.com/" target="_parent">data for b</a></td>
    <td class="numericalColumn">522273</td>
    <td class="numericalColumn">B</td></tr>
.
.
.100 <tr> here
.
  </tbody>
 </table>
</td>
<td style="padding-right>
 <table class = dataTabe>
  <tbody>
   <tr>
   <td><a HREF="http://c.com/" target="_parent">data for c</a></td>
   <td class="numericalColumn">526735</td>
   <td class="numericalColumn">Z</td></tr>
  <tr>
   <td><a HREF="http://d.com/" target="_parent">data for d</a></td>
   <td class="numericalColumn">522273</td>
   <td class="numericalColumn">B</td></tr>
.
.
.100 rows here
.
  </tbody>
 </table>      
</td>
</tr>
</tbody>
</table>

This is the class used to get the data.

import java.io.BufferedReader;
import java.io.InputStream;
import org.w3c.tidy.*;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.tidy.Node;
import org.w3c.tidy.Tidy;
import org.w3c.tidy.Tidy;

public class CompaniesGetter {
public static void main(String[] args) throws Exception{
    String name,link,scripcode,group,s,key;
    int a=1;
    int count=1;
    URL oracle = new URL("http://money.rediff.com/companies");
    URLConnection yc = oracle.openConnection();
    InputStream is = yc.getInputStream();
    is = oracle.openStream();
    Tidy tidy = new Tidy();
    tidy.setQuiet(true);
    tidy.setShowWarnings(false);
    Document tidyDOM = tidy.parseDOM(is, null);
    XPathFactory xPathFactory = XPathFactory.newInstance();
    XPath xPath = xPathFactory.newXPath();
    Map<String,String> mLink=new HashMap<String,String>();
    Map<String,String> mCode=new HashMap<String,String>();
    Map<String,String> mGroup=new HashMap<String,String>();
    ArrayList<String> aName=new ArrayList<String>();
    //for(int j=0;j<2;j++)
    for(int i =1;i<=200;i++)
    {if(i==100)
    {
        a=2;
        s=attrib[1];
    }
        link = "//table[@class='dataTable']/tbody/tr["+i+"]/td/a/@href";
        name = "//table[@class='dataTable']/tbody/tr["+i+"]/td/a";
        scripcode = "//table[@class='dataTable']/tbody/tr["+i+"]/td[2]";
        group = "//table[@class='dataTable']/tbody/tr["+i+"]/td[3]";
        String linkValue = (String)xPath.evaluate(link, tidyDOM, XPathConstants.STRING);
        String nameValue = (String)xPath.evaluate(name, tidyDOM, XPathConstants.STRING);
        String scripValue = (String)xPath.evaluate(scripcode, tidyDOM, XPathConstants.STRING);
        String groupValue = (String)xPath.evaluate(group, tidyDOM, XPathConstants.STRING);
        aName.add(nameValue);
        mLink.put(nameValue, linkValue);
        mCode.put(nameValue, scripValue);
        mGroup.put(nameValue,groupValue);
    }
    Iterator<String> itr=aName.iterator();
    while (itr.hasNext()){
        key=itr.next();
        System.out.println("::"+(count++)+" "+key + "  "+mLink.get(key)+"   "+mCode.get(key)+"   "+mGroup.get(key)+" ::");
    }

}

}
  • 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-05-24T19:27:10+00:00Added an answer on May 24, 2026 at 7:27 pm

    Hm. Just a tip: Do you use the variable “a” in the XPaths?

    link = "//table[@class='dataTable']/tbody/tr["+i+"]/td/a/@href";
    

    should be

    link = "//table[@class='dataTable'][" + a + "]/tbody/tr["+i+"]/td/a/@href";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently building an application using Tomcat, Spring and JAVA. I am using
I'm building a Java Web Application using Java EE 6 and JSF-2.0, using the
I am building a client server application using Java Sockets (in Windows XP). For
I'm building an application using Java and Mysql 5.1. i would like to know
I am building an application in Java using Netbeans IDE. I am trying to
I am building a social web application using Java and Cassandra DB. I want
I'm building a Java application (using Ant with build.xml and build.property files). Now I'd
I am building my first Java application using GWT which must read in data
I'm building a personal Web application using Java EE 6 Technologies (the container is
I'm building a java application which works in a LAN environment, every computer on

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.