Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieval of text on a web page using C++

Status
Not open for further replies.

thebarslider

Programmer
Dec 21, 2001
80
0
0
GB

Hey there everyone hope everyones having fun coding away...

I'm having a little problem. I wish to retrieve text from a web page and use it within my C++ (MFC) programme. Is there any special functions i can call that will load up a URL and then a function that will parse it?

Also the web page i'm trying to access changes everyday, so is it possible to get my program to follow links from the base URL to find the correct page? I.e. i will supply it with relevant search criteria.

Would it be easier to use some sort of language extension? XML?

Your comments would be much appreciated.

Thank you again.

Mark.
 
For getting the page content u can use the WININET MFC wrappers. Look at CHttpConnection

For parsing the HTML there is nothing built in to MFC for this. u might find something on the net if u look for it. If the Html is well formed xml then u can use the MSXML parser and DOM.

Good luck

-pete
 
Here's an example that reads the URL as a string. NOTE: depending on the content of the URL the string may or may not retrieve the entire text. You'll need to look more into the CHTTPFile class for information:[tt]

CInternetSession* inetSession =
new CInternetSession("Your App Name",1,
INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);

CString url = "CHttpFile* file = (CHttpFile*)inetSession->
OpenURL(url,1,
INTERNET_FLAG_TRANSFER_ASCII|
INTERNET_FLAG_RELOAD,NULL,0);

file->ReadString(url);
file->Close();
delete inetSession;

[/tt]The response from the URL is then placed into the original CString object called 'url'

"I've found your posts in this thread to be mostly childish and immaterial"
- That wouldn't happen to have been the 'C' forum by any chance would it? LOL
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top