Solved

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

Posted on 2006-11-04
7
716 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 Comments
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

627 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