#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3VybC9jdXJsLmg+CiNpbmNsdWRlICJwdWdpeG1sLmhwcCIKI2luY2x1ZGUgPHJlZ2V4PgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCi8vIENhbGxiYWNrIGZ1bmN0aW9uIHRvIHdyaXRlIGRhdGEgcmVjZWl2ZWQgZnJvbSBjVVJMIHJlcXVlc3QKc2l6ZV90IFdyaXRlQ2FsbGJhY2sodm9pZCogY29udGVudHMsIHNpemVfdCBzaXplLCBzaXplX3Qgbm1lbWIs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1hdXRob3Itb25seS4uLmUub3JnLy4qP1wubXAzKSkiKTsKICAgIHNtYXRjaCBtYXRjaGVzOwogICAgc3RyaW5nOjpjb25zdF9pdGVyYXRvciBzZWFyY2hTdGFydChodG1sLmNiZWdpbigpKTsKCiAgICB3aGlsZSAocmVnZXhfc2VhcmNoKHNlYXJjaFN0YXJ0LCBodG1sLmNlbmQoKSwgbWF0Y2hlcywgYXVkaW9SZWdleCkpIHsKICAgICAgICBjb3V0IDw8ICJQcm9udW5jaWF0aW9uIGxpbms6ICIgPDwgbWF0Y2hlc1sxXSA8PCBlbmRsOwogICAgICAgIHNlYXJjaFN0YXJ0ID0gbWF0Y2hlcy5zdWZmaXgoKS5maXJzdDsKICAgIH0KfQoKaW50IG1haW4oKSB7CiAgICBzdHJpbmcgd29yZHNbXSA9IHsicGVyc29uYWwiLCAibmF0dXJhbCIsICJuYXRpb25hbGl0eSIsICJhdG1vc3BoZXJlIn07CgogICAgZm9yIChjb25zdCBzdHJpbmcmIHdvcmQgOiB3b3JkcykgewogICAgICAgIHN0cmluZyB1cmwgPSAiaHR0cHM6Ly9kLi4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5lLm9yZy9kaWN0aW9uYXJ5L2VuZ2xpc2gvIiArIHdvcmQ7CiAgICAgICAgY291dCA8PCAiRmV0Y2hpbmcgcHJvbnVuY2lhdGlvbiBmb3I6ICIgPDwgd29yZCA8PCBlbmRsOwogICAgICAgIHN0cmluZyBodG1sQ29udGVudCA9IGZldGNoSFRNTCh1cmwpOwogICAgICAgIGV4dHJhY3RQcm9udW5jaWF0aW9uTGlua3MoaHRtbENvbnRlbnQpOwogICAgICAgIGNvdXQgPDwgIi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0iIDw8IGVuZGw7CiAgICB9CiAgICByZXR1cm4gMDsKfQo=
#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;
}