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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:43:54+00:00 2026-06-01T15:43:54+00:00

I am trying to obtain the text content of a Internet Explorer web browser

  • 0

I am trying to obtain the text content of a Internet Explorer web browser window.

I am following these steps:

  1. obtain a pointer to IHTMLDocument2
  2. from the IHTMLDocument2 i obtain the body as an IHTMLElement
    3. On the body i call get_innerText

Edit


  1. I obtain all the children of the body and try to do a recursive call on all the IHTMLElements
  2. if i get any element which is not visible or if i get an element whose tag is script, i ignore that element and all its children.

My problem is

  1. that along with the text which is visible on the page i also get content having for which style=”display: none”
  2. For google.com, i also get javascript along with the text.

I have tried a recursive approach, but i am clueless as to how to deal with scenarios like this,

<div>
Hello World 1
<div style="display: none">Hello world 2</div>
</div>

In this scenario i wont be able to get “Hello World 1”

Can anyone please help me out with the best way to obtain the text from an IHTMLDocument2*.
I am using C++ Win32, no MFC, ATL.

Thanks,
Ashish.

  • 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-01T15:43:55+00:00Added an answer on June 1, 2026 at 3:43 pm

    If you iterate backwards on the document.body.all elements, you will always walk on the elements inside out. So you don’t need to walk recursive yourself. the DOM will do that for you. e.g. (Code is in Delphi):

    procedure Test();
    var
      document, el: OleVariant;
      i: Integer;
    begin
      document := CreateComObject(CLASS_HTMLDocument) as IDispatch;
      document.open;
      document.write('<div>Hello World 1<div style="display: none">Hello world 2<div>This DIV is also invisible</div></div></div>');
      document.close;
      for i := document.body.all.length - 1 downto 0 do // iterate backwards
      begin
        el := document.body.all.item(i);
        // filter the elements
        if (el.style.display = 'none') then
        begin
          el.removeNode(true);
        end;
      end;
      ShowMessage(document.body.innerText);
    end;
    

    A Side Comment:
    As for your scenario with the recursive approach:

    <div>Hello World 1<div style="display: none">Hello world 2</div></div>
    

    If e.g. our element is the first DIV, el.getAdjacentText('afterBegin') will return "Hello World 1". So we can probably iterate forward on the elements and collect the getAdjacentText('afterBegin'), but this is a bit more difficult because we need to test the parents of each element for el.currentStyle.display.

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

Sidebar

Related Questions

I am trying to obtain and transfer information from a HTML web form (through
I am trying to obtain the ip address from a text file so when
I'm trying to obtain the text shown in a MS Word window in C#
I'm trying to obtain a result from a web service in a java program.
I'm currently having an issue when trying to obtain the current selected text from
I am trying to obtain data from a Web and show it to the
I am trying to obtain some information from a webpage that requires login. I
After trying for two months I find out how to obtain AttributedString from any
I am trying to obtain JSON object in the following code. The problem is,
I am trying to obtain embeded code through extracting variables from Youtube video URLs.

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.