#include <iostream>
#include <curl/curl.h>
size_t WriteCallback(void contents, size_t size, size_t nmemb, std::string output) {
size_t totalSize = size * nmemb;
output->append(static_cast<char*>(contents), totalSize);
return totalSize;
}
int main() {
CURL* curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
std::string response;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
else {
if(response.find("google_ad_client") != std::string::npos)
std::cout << "AdSense code found on the page." << std::endl;
else
std::cout << "No AdSense code found on the page." << std::endl;
}
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}