I am trying to use Poco to grab news from the front page of reddit. I'm looking at this pdf ( http://pocoproject.org/slides/200-Network.pdf ) for the answer, but it's a bit over my head at this point and I'm not sure how to accomplish my goal. As I said, I'm trying to simply grab the news articles (specifically, the article titles) from www.reddit.com.
The code I have so far grabs ALL off the html from reddit's front page and cout's it to the screen:
#include <iostream>
#include "Poco/Net/SocketAddress.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/Net/SocketStream.h"
#include "Poco/StreamCopier.h"
using namespace std;
using namespace Poco::Net;
using namespace Poco;
int main(int argc, char *argv[])
{
SocketAddress sa("www.reddit.com", 80);
StreamSocket socket(sa);
SocketStream str(socket);
str << "GET / HTTP/1.1\r\n"
"Host: www.reddit.com\r\n"
"\r\n";
str.flush();
StreamCopier::copyStream(str, cout);
system("PAUSE");
}
Looking at the above mentioned pdf, it looks like my answer may be in there somewhere, but I am still learning about computer networks and internet protocol, so most of it is above my head at this point.
Main Question: Can someone help me figure out how to get the article titles from www.reddit.com into a string or array of strings?
<a class="titleseems like a starting point for determining title text. Something less brittle might be using HTML Tidy + some SAX/DOM parser.StreamCopier::copyStream(str, cout);when it outputs the data to the console, I need to find a way to get that data into a string (which I don't know how to do, but believe me I am trying). I'm honestly not worried about the string parsing, I've done that a bunch of times. It's just that I need to get the data into a string. I just figured that I might have to do that through the POCO libraries, hence my question.