fork download
  1. #include <iostream>
  2. #include <curl/curl.h>
  3. #include "pugixml.hpp"
  4. #include <regex>
  5.  
  6. using namespace std;
  7.  
  8. // Callback function to write data received from cURL request
  9. size_t WriteCallback(void* contents, size_t size, size_t nmemb, string* output) {
  10. size_t totalSize = size * nmemb;
  11. output->append((char*)contents, totalSize);
  12. return totalSize;
  13. }
  14.  
  15. // Function to fetch HTML content using cURL
  16. string fetchHTML(const string& url) {
  17. CURL* curl;
  18. CURLcode res;
  19. string response;
  20.  
  21. curl = curl_easy_init();
  22. if (curl) {
  23. curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
  24. curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
  25. curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
  26. curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  27. res = curl_easy_perform(curl);
  28. curl_easy_cleanup(curl);
  29. }
  30. return response;
  31. }
  32.  
  33. // Function to extract pronunciation URLs using regex
  34. void extractPronunciationLinks(const string& html) {
  35. regex audioRegex(R"((https://d...content-available-to-author-only...e.org/.*?\.mp3))");
  36. smatch matches;
  37. string::const_iterator searchStart(html.cbegin());
  38.  
  39. while (regex_search(searchStart, html.cend(), matches, audioRegex)) {
  40. cout << "Pronunciation link: " << matches[1] << endl;
  41. searchStart = matches.suffix().first;
  42. }
  43. }
  44.  
  45. int main() {
  46. string words[] = {"personal", "natural", "nationality", "atmosphere"};
  47.  
  48. for (const string& word : words) {
  49. string url = "https://d...content-available-to-author-only...e.org/dictionary/english/" + word;
  50. cout << "Fetching pronunciation for: " << word << endl;
  51. string htmlContent = fetchHTML(url);
  52. extractPronunciationLinks(htmlContent);
  53. cout << "----------------------------------" << endl;
  54. }
  55. return 0;
  56. }
  57.  
Success #stdin #stdout 0.03s 25732KB
stdin
Standard input is empty
stdout
#include <iostream>
#include <curl/curl.h>
#include "pugixml.hpp"
#include <regex>

using namespace std;

// Callback function to write data received from cURL request
size_t WriteCallback(void* contents, size_t size, size_t nmemb, string* output) {
    size_t totalSize = size * nmemb;
    output->append((char*)contents, totalSize);
    return totalSize;
}

// Function to fetch HTML content using cURL
string fetchHTML(const string& url) {
    CURL* curl;
    CURLcode res;
    string response;

    curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }
    return response;
}

// Function to extract pronunciation URLs using regex
void extractPronunciationLinks(const string& html) {
    regex audioRegex(R"((https://d...content-available-to-author-only...e.org/.*?\.mp3))");
    smatch matches;
    string::const_iterator searchStart(html.cbegin());

    while (regex_search(searchStart, html.cend(), matches, audioRegex)) {
        cout << "Pronunciation link: " << matches[1] << endl;
        searchStart = matches.suffix().first;
    }
}

int main() {
    string words[] = {"personal", "natural", "nationality", "atmosphere"};

    for (const string& word : words) {
        string url = "https://d...content-available-to-author-only...e.org/dictionary/english/" + word;
        cout << "Fetching pronunciation for: " << word << endl;
        string htmlContent = fetchHTML(url);
        extractPronunciationLinks(htmlContent);
        cout << "----------------------------------" << endl;
    }
    return 0;
}