tags:

views:

150

answers:

4

Hello, I was wondering if anyone knew how to read text from a webpage from within C++.

After you first connect to the internet using usual means,

you enter the string e.g. "http://www.bbc.co.uk" and the C++ program reads the information:

"BBC WebsiteThis is the BBC website...."

from the internet.

Would I have to write a program that sends lots of data to and from the modem to do this or is there a simpler way of doing this? Is there some sort of command line program in Windows that does this all for you? Either way if you have any tips of know of any tutorials on the web that would be great.

I would like to know because I think it would be fun to write applications that could read information off the internet, follow links and so forth and I might think of a good game that utilises this.

Thank.

Paul.

+1  A: 

You could use wget to fetch pages, but you would still need to parse the output.

You don't need to send data to the modem. All you need to do is connect to the webserver via sockets and retrieve the data from there. Look for literature on socket programming and the http-protocol.

EricSchaefer
Whats the downvoting for? Is there anything wrong with my answer?
EricSchaefer
ya you replied to a duplicate question
You must be kidding. If the question is a duplicate than either put up a comment to the the question with a link to the dupe and request the question to be closed or vote down the QUESTION, not the answers of people who want to help. If I am supposed to figure out if a question is a dupe before ...
EricSchaefer
... I answer it, I will never ever answer any questions. But it is the responsibility of the person who ASKS a question to check if it has been asked before. Maybe you didn't quite understand how SO is supposed to work...
EricSchaefer
Looks like you did post the link to the dupe, but eight minutes after my answer.... Go figure...
EricSchaefer
well the idea is that you delete your answer when you see that something's fishy. lets keep SO clean
Whatever. To keep SO clean, you would have to delete the question, not downvote the answers...
EricSchaefer
yeah. i was wrong on this. sry. ;)
A: 

Not directly from C++, but sources are available: there is Lynx text browser.

mouviciel
+2  A: 

You can do this pretty easily with boost. Check Asio.

Http Client Example (downloads and displays a .txt file from the internet)

drby
+4  A: 

I would recommend lib cURL for http in C/C++ but that still leaves out parsing the html to render the actual text from tags.

Tim Matthews