Solved

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

Posted on 2006-11-04
7
693 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

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do you programatically show and hide the Windows 10 On-Screen-Keyboard? 3 1,032
either24  challenge 19 110
EvenOdd challenge 10 160
Problem to App source 6 120
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

710 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