How to Convert a URL to Plain Text using C/C++

Retrieving plain text from any web page is simple in theory — but a bit of a chore in practice. We need to strip that text from the HTML elements encasing it, and doing so requires writing our own code or manually pointing-and-clicking our way through the entire process.
Thankfully, using the below code, you leverage a free API that automatically strips plain text from HTML via the web page URL. You’ll receive a quick response containing the entire page’s plain & unformatted text contents, and you can easily store or share that information however you see fit.
To begin structuring your API request, you’ll need to first make sure libcurl is installed in your C/C++ project:
libcurl/7.75.0
After that, you can copy and paste the below code examples into your file and provide a free-tier Cloudmersive API key to authenticate your requests:
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.cloudmersive.com/convert/web/url/to/txt");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "Url=%3Cstring%3E";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
You can get your API key easily by registering a free account on the Cloudmersive website. This allows a limit of 800 API calls per month and no additional commitment.
That’s all there is to it — now you can enjoy a quick & easy URL to text conversion service in any of your C/C++ applications.