0

Need: Parse a web page and read the details presented in a table (Web Page to parse - Link)

Issue: I am unable to get the details under tbody section. At present I am only able to get thead details.

Research: I checked with this Link on stack overflow, but unable to figure out in my case.

The HTML table which I need to extract

<table id="industryInfo" class="eq-series tbl-securityinfo cap-hide">
           <caption></caption>
           <thead>
                    <tr>
                          <th>Macro-Economic Sector</th>
                          <th>Sector</th>
                          <th>Industry</th>
                          <th>Basic Industry</th>
                    </tr>
           </thead>
           <tbody class="">
                    <tr>
                         <td>Commodities</td>
                         <td>Metals & Mining</td>
                         <td>Ferrous Metals</td>
                         <td>Pig Iron</td>
                    </tr>
           </tbody>
</table>

Code:

    String url = "https://www.nseindia.com/get-quotes/equity?symbol=ADANIENT";
    Document document = new Document(url);
        try {
               document = Jsoup.connect(url).userAgent("Mozilla/5.0").get();
        } catch (IOException e) {
            e.printStackTrace();
        }
//        System.out.println(document);
        Elements elements = document.select("#industryInfo");
        for (Element element : elements) {
            System.out.println(element);
        }

Hope the issue faced is clear, any pointers to what I am missing will be helpful

iCoder
  • 1,406
  • 6
  • 16
  • 35
  • 1
    It looks like content of that page is added dynamically by some script (usually JavaScript) *after* page is loaded. Jsoup is not browser *emulator* and doesn't support execution of JavaScript code. Either change tool to something which supports JavaScript like Selenium webdriver, or use your browser developers tools to observe what requests that page make to *load* that information. When you know it you can try reading from same place. – Pshemo Dec 29 '22 at 11:42
  • 1
    From what I see `https://www.nseindia.com/api/quote-equity?symbol=ADANIENT` returns JSON with data (also) for that table. Parse it and search things you want. – Pshemo Dec 29 '22 at 11:46

0 Answers0