VB icon

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

Email
Submitted on: 1/6/2015 9:14:00 AM
By: fritz0x00 (from psc cd)  
Level: Advanced
User Rating: By 4 Users
Compatibility: C++ (general), Microsoft Visual C++
Views: 5092
 
     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!
				
//**************************************
// 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 (from psc cd)
//
// Assumes:Make sure to define m_strURL and m_strSource via ClassWizard
//**************************************

//** 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 5 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


 There are no comments on this submission.
 

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.