想要爬取第一条网页的数据但是失败了
CURL *curl = curl_easy_init();
if (curl) {
std::string lurl;
lurl = "https://www.nasdaq.com/market-activity/stocks/amzn/historical";
curl_easy_setopt(curl, CURLOPT_URL, lurl.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
std::string html_data;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &html_data);
CURLcode res = curl_easy_perform(curl);
if (res == CURLE_OK) {
std::cout << html_data.substr(0, 50) << std::endl;
}
else {
std::cerr << "Failed to download HTML: " << curl_easy_strerror(res) << std::endl;
}
std::cout << std::endl << std::endl;
lurl = "https://finance.sina.com.cn/";
curl_easy_setopt(curl, CURLOPT_URL, lurl.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &html_data);
res = curl_easy_perform(curl);
if (res == CURLE_OK) {
std::cout << html_data.substr(0, 50) << std::endl;
}
else {
std::cerr << "Failed to download HTML: " << curl_easy_strerror(res) << std::endl;
}
curl_easy_cleanup(curl);
}