Test for HTTP status
[dueringa_WikiWalker.git] / src / WikiWalker.cpp
blobb3f7c9bc54d0f3925b1cfc1c7493133e5cbfc95b
1 #include "WikiWalker.h"
3 #include <iostream>
5 using namespace std;
7 void WikiWalker::startWalking(string url)
9 std::string findUrl = "en.wikipedia.org/wiki/";
10 size_t pos = url.find(findUrl);
11 if(pos == string::npos) {
12 throw WalkerException("Must be an English Wikipedia URL");
15 // extract Wikipedia title
16 std::string title = url.substr(pos + findUrl.length());
18 // TODO: little bobby tables?
19 auto content = grabber.grabUrl("https://en.wikipedia.org/w/api.php?action=query&format=json&prop=links&pllimit=50&plnamespace=0&titles=" + title);
21 if(content.getTitle() != "")
23 std::cout << "Article " << content.getTitle() << " has " << content.getNumLinks() << " links" << std::endl;
25 else
27 std::cerr << "Error fetching article" << std::endl;