Important alert: (current site time 7/15/2013 5:34:38 PM EDT)
 

VB icon

^!!~ A better HTML Source Grabber/Stealer ~!!^

Email
Submitted on: 3/22/2004 11:35:43 PM
By: fritz0x00  
Level: Advanced
User Rating: By 4 Users
Compatibility: C++ (general), Microsoft Visual C++
Views: 26138
author picture
(About the author)
 
     Simple example of how to grab(some people like ti call it 'steal') the HTML source of a page from a application... There are a couple of examples here at PSC, but they are not very good because they use ReadHuge to store all of the data in a buffer which can cause memory problems, incomplete page sources, and of course ugly boxes due to no carriage returns or line breaks... This ReadString version is alot more efficent... It works 100% in MFC... And since this code is so easy to implement into virtually any project, I am NOT going to post the project files unless I get alot of requests
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :^!!~ A better HTML Source Grabber/Stealer ~!!^
//**************************************
#include <afxinet.h>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: ^!!~ A better HTML Source Grabber/Stealer ~!!^
// Description:Simple example of how to grab(some people like ti call it 'steal') the HTML source of a page from a application... There are a couple of examples here at PSC, but they are not very good because they use ReadHuge to store all of the data in a buffer which can cause memory problems, incomplete page sources, and of course ugly boxes due to no carriage returns or line breaks... This ReadString version is alot more efficent... It works 100% in MFC... And since this code is so easy to implement into virtually any project, I am NOT going to post the project files unless I get alot of requests
// By: fritz0x00
//
// Assumes:Make sure to define m_strURL and m_strSource via ClassWizard
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=7754&lngWId=3//for details.//**************************************

//** Make sure you add two edit boxes to your dialog, make the one for the URL input a CString named 'm_strURL'
//** And to store the source add another edit box(Make sure its multi line), make it a CString named 'm_strSource'
void CYourDialogClass::OnYourEvent()
{
	UpdateData(TRUE); //** Perform DDX and get user input
	CInternetSession session; //** define our internet session
	CInternetFile* pFile = (CInternetFile *)session.OpenURL(m_strURL); //** define our internet file that will hold the source
	if(pFile) //** If we can OpenURL(m_strURL)
	{
		CString string; //** Create a buffer string
		while (pFile->ReadString(string) != NULL) //** Read as many string as we can until we run into EOF(End Of File)
		{
			m_strSource += string; //** Add the string of data we just read
			m_strSource += "\r\n"; //** Add a line break to make it look better
		}
	}
	UpdateData(FALSE); 	
}


Other 6 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

7/18/2004 3:21:05 PM

r5rtrsrtews
(If this comment was disrespectful, please report it.)

 
9/30/2004 11:23:56 AM

Hi Zak,
Tried to send you an email.... that doesn't work... for some reason. I like what you posted. Consider this a request to see the project files, that you seem to not want to post.
(If this comment was disrespectful, please report it.)

 
10/3/2004 11:38:09 AMAJ1

Hi Zak,
I get 8 undefined errors. What header am I missing?

Thanks,
AJ.
(If this comment was disrespectful, please report it.)

 
10/3/2004 11:47:10 AMAJ1

Got it. Sorry for the dum question.

AJ.
(If this comment was disrespectful, please report it.)

 
10/3/2004 11:53:40 AMAJ1

Works perfectly. Good job. 5 globes from me.

AJ
(If this comment was disrespectful, please report it.)

 
2/16/2005 4:49:54 AM

What happend when I ran the application:
...
Detected memory leaks!
Dumping objects ->
inet.cpp(882) : {89} normal block at 0x00326C90, 4096 bytes long.
...
If you can give me a solution to this problem...
(If this comment was disrespectful, please report it.)

 
9/26/2005 11:19:02 PMMichael

perfect and concise: 5 globes from me, thanks :)
(If this comment was disrespectful, please report it.)

 
8/22/2006 7:17:43 AMraja

good
(If this comment was disrespectful, please report it.)

 
10/17/2006 10:47:26 AMMazi

^!!~ A better HTML Source Grabber/Stealer ~!!^


hello can you please email me the projekt ? I realy want to know how it is done.
(If this comment was disrespectful, please report it.)

 
3/17/2008 8:56:26 AMGabi

Can you pls Send or publis the code Files I Cant make it work
(If this comment was disrespectful, please report it.)

 
3/17/2008 8:58:29 AMGabi

Can You pls publish the code files
cant make ut work
(If this comment was disrespectful, please report it.)

 
5/31/2008 12:49:53 AMXerox

In mozilla firefox u can take the page source by clicking on view and pressing page source it gives u the codes of the page. then u can modify it by urself using C++
(If this comment was disrespectful, please report it.)

 
5/27/2009 10:57:00 AMhothi_vuong@yahoo.com

hothi_vuong@yahoo.com
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.