Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to read the HTML source with CViewHtml or URL with MFC?

Posted on 2006-11-04
7
Medium Priority
?
747 Views
Last Modified: 2013-11-20
Hi Experts,

I have developed a class that driver the CViewHtml to browser HTML from a URL,
Now, I want to get all the contents of html page to save to the local html file, how can I do this?
How we reat the html contents from a URL? or read the contents from CViewHtml control?

Thank in advance!
0
Comment
Question by:Mobinex
  • 3
4 Comments
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 2000 total points
ID: 17876373
You can use GetHtmlDocument() and then manipulate the document directly save it, change it, etc.

You may use code similar to following :

e.g.

// Note:  CMyHtmlView is derived from CHtmlView

CString CMyHtmlView::GetHtmlText()
{
 CString Text;
 HRESULT hr;
 IHTMLDocument2 *pDoc = NULL;

 // Load the current document into pDoc
 hr = this->GetHtmlDocument()->QueryInterface(IID_IHTMLDocument2, (void **) &pDoc);

 if (hr == S_OK)
 {
  BSTR pelementText = NULL;
  IHTMLElement *Element = NULL;

  // Get the body
  pDoc->get_body(&Element);

  Element->get_innerHTML(&pelementText);
  Text = pelementText;

 } // End HTMLdocument is valid (HR == OK)

 return Text;
}

Hope this helps
-MAHESH
0
 
LVL 1

Author Comment

by:Mobinex
ID: 17878589
Many thank for this,
I have question next. How to get images infomation to download to client? Can we cache all images and text with CViewHtml to app folder(my ower folder)?

Thank in advance!
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17879015
For images you may use IHTMLDocument2::get_images() and IHTMLImgElement

Have a Look here : http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20294289.html

-MAHESH
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17879082
Alternatively you may use UrlDownloadToFile() API function to download elements, images, entire webpage to disk.
http://msdn.microsoft.com/workshop/networking/moniker/reference/functions/urldownloadtofile.asp

-MAHESH
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question