开发者

Need help to get an html and use in C like a text file in fopen

I want to get a HTML and use like a file in C. Actually I can do that, but I have to save the file first on the disk and then use fopen("/file.html", "r");. What I would like to do is to extract the html directly from the URL and work with it.

Hypothetically, fopen("http://www.google.com", "r");

I saw something about libcurl开发者_开发技巧 but I don't know if it will help me.


You can do something as simple as:

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

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

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");
    res = curl_easy_perform(curl);

    /* always cleanup */ 
    curl_easy_cleanup(curl);
  }
  return 0;
}

Source: Using cURL in C

You can get the complete function documentations here: Using The libcurl C Interface

This PDF link will help you in using libcurl in VS


Yes, I think cURL would be a good choice.

C libcurl get output into a string


libcurl should get you what you need. See the code sample here: http://curl.haxx.se/libcurl/c/fopen.html

This will allow you to "read remote streams instead of (only) local files".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜