0

我在 C 中使用 Curl,但我不想回显网页代码:

CURL *curl;
curl = curl_easy_init();

curl_easy_setopt(curl, CURLOPT_URL, "www.example.com");

curl_easy_perform(curl);    
curl_easy_cleanup(curl);

有任何卷曲选项吗?

4

1 回答 1

0

我为这个问题找到了一个很好的解决方案:

size_t function(void *ptr, size_t size, size_t nmemb, FILE *stream) {
    return fwrite(ptr, size, nmemb, stream);
}

...

FILE *outfile;
outfile = fopen("test", "w");

CURL *curl;
curl = curl_easy_init();

curl_easy_setopt(curl, CURLOPT_URL, "www.example.com");
curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, function);

curl_easy_perform(curl);    
curl_easy_cleanup(curl);

您可以在文件中打印 html 代码,而不是在“控制台”中打印

于 2013-10-14T16:09:06.880 回答