1 #include "CurlWikiGrabber.h"
3 static size_t write_callback(char *ptr
, size_t size
, size_t nmemb
, void *userdata
)
5 static_cast<std::string
*>(userdata
)->append(ptr
, size
* nmemb
);
9 CurlWikiGrabber::CurlWikiGrabber()
11 int error
= curl_global_init(CURL_GLOBAL_ALL
);
14 throw WalkerException("CURL init failed");
18 //! \todo change to passing page title?
19 //! \todo Curl return code checking
20 std::string
CurlWikiGrabber::grabUrl(std::string url
) const
22 CURL
*handle
= curl_easy_init();
26 throw WalkerException("error initiating curl");
29 curl_easy_setopt(handle
, CURLOPT_URL
, url
.c_str());
30 curl_easy_setopt(handle
, CURLOPT_USERAGENT
, "WikiWalker/ test program");
31 curl_easy_setopt(handle
, CURLOPT_WRITEFUNCTION
, write_callback
);
32 std::string gotContent
;
33 curl_easy_setopt(handle
, CURLOPT_WRITEDATA
, &gotContent
);
37 curl_easy_perform(handle
);
40 curl_easy_getinfo(handle
, CURLINFO_RESPONSE_CODE
, &httpcode
);
42 curl_easy_cleanup(handle
);
53 // https://en.wikipedia.org/w/api.php
54 // /w/api.php?action=query&format=json&prop=links&plnamespace=0&titles=<title>