1 #include "WikiWalker.h"
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
;
27 std::cerr
<< "Error fetching article" << std::endl
;