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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:21:41+00:00 2026-06-08T11:21:41+00:00

What I am trying to do is scrape a simple inner HTML from a

  • 0

What I am trying to do is scrape a simple inner HTML from a XHTML file.
I have narrowed down my search to the element node, but I fail to retrieve the information.

PLEASE NOTE: the element node has no child node. I get a null pointer exception for doing that

here is the HTML SNIPPET

    <div id="dvTitle" class="titlebtmbrdr01" style="line-height: 22px;">BAJAJ AUTO LTD.       </div>

PLease also NOTE that this file has namespace as
http://www.w3.org/1999/xhtml

You can see that I have the div element from which I want BAJAJ AUTO LTD.

Here is the code that i am using

    import java.io.IOException;
     import java.net.MalformedURLException; 
      import java.net.URL;
      import java.util.Vector;

    import javax.xml.xpath.XPath;
    import javax.xml.xpath.XPathConstants;
    import javax.xml.xpath.XPathExpression;
      import javax.xml.xpath.XPathExpressionException;
    import javax.xml.xpath.XPathFactory;

    import jxl.read.biff.BiffException;
    import jxl.write.WriteException;
    import jxl.write.biff.RowsExceededException;

    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
      import org.w3c.dom.Node;
      import org.w3c.dom.NodeList;
    import org.w3c.dom.Text;

    import com.sun.org.apache.xml.internal.serialize.Serializer;


    public class BSEQuotesExtractor implements valueExtractor {

@Override
public Vector<String> getName(Document d) throws XPathExpressionException,            RowsExceededException, BiffException, WriteException, IOException {
    // TODO Auto-generated method stub
    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    xpath.setNamespaceContext(new MynamespaceContext());


    Object result = xpath.evaluate("//*[@id='dvTitle']",d, XPathConstants.NODESET);
    NodeList nodes = (NodeList) result;

    System.out.println(nodes.getLength());
    System.out.println(nodes.item(0).getNodeName());
    System.out.println(nodes.item(0).getAttributes().item(1).getNodeName());
    System.out.println(nodes.item(0).getAttributes().item(1).getNodeValue());
    System.out.println(nodes.item(0).getTextContent());

    return null;
}

public static void main(String[] args) throws MalformedURLException, IOException, XPathExpressionException, RowsExceededException, BiffException, WriteException{
    BSEQuotesExtractor q = new BSEQuotesExtractor();
    DOMParser parser = new DOMParser(new URL("http://www.bseindia.com/bseplus/StockReach/StockQuote/Equity/BAJAJ%20AUTO%20LTD/BAJAJAUT/532977/Scrips").openStream());
    Document d = parser.getDocument();
    q.getName(d);

}

        }

And this is the output I get

1
div
dvTitle
null

Now why do I get that null? I should get BAJAJ AUTO LTD.

  • 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-08T11:21:43+00:00Added an answer on June 8, 2026 at 11:21 am

    When I open the page your code references, that div actually is empty for me:

    <div class="titlebtmbrdr01" id="dvTitle" style="line-height: 22px;"></div>
    

    So perhaps you should save the page content to some file to examine if it is the same for you. If it is, but your browser displays things differently, then figure out what combination of cookies and other headers makes a difference there.

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

Sidebar

Related Questions

I'm trying to scrape all the inner html from the <p> elements in a
Trying to scrape images and data from a website using Xpath but keeps showing
I have been trying to get a simple spider to run with scrapy, but
I have been trying to data scrape the current value of a stock from
I have been trying to scrape the 'School Notices' from this URL http://www.isleworthsyon.hounslow.sch.uk/ I
I am trying to scrape the datas from a webpage, but I get need
I'm trying to scrape the price field from this website using the HTML Agility
Trying to scrape data from totalfilm.com using YQL but I'm getting a strange error:
I am trying to scrape the text only from body using python Scrapy, but
I'm trying to scrape some information from a web site, but am having trouble

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.