0
点赞
收藏
分享

微信扫一扫

libcurl库的网页爬虫程序

libcurl库的网页爬虫程序_示例代码

  • 示例代码:

#include <curl/curl.h>
#include <iostream>

int main() {
    CURL *curl;
    CURLcode res;

    curl_global_init(CURL_GLOBAL_DEFAULT);

    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "/");
        curl_easy_setopt(curl, CURLOPT_PROXY, "");
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL); // 使用默认的写入函数
        curl_easy_setopt(curl, CURLOPT_ERRORFUNCTION, NULL); // 使用默认的错误处理函数

        res = curl_easy_perform(curl);

        if(res != CURLE_OK)
            std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;

        curl_easy_cleanup(curl);
    }

    curl_global_cleanup();

    return 0;
}

解释:

举报

相关推荐

0 条评论