Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the most efficient way to get source code of web page in C?

Tags:

c

networking

In PHP I can do it as simple as :

file_get_contents('http://stackoverflow.com/questions/ask');

What's the shortest code to do the same in C?

UPDATE

When I compile the sample with curl, got errors like this:

unresolved external symbol __imp__curl_easy_cleanup referenced in function _main 
like image 830
ieplugin Avatar asked Jul 05 '10 14:07

ieplugin


People also ask

How do I download source code?

To download a website's HTML source code, navigate using your favorite browser to the page, and then select SAVE PAGE AS from the FILE menu. You'll then be prompted to select whether you want to download the whole page (including images) or just the source code. The download options are common for all browsers.


2 Answers

Use libcurl, refer to their example C snippets

#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, "curl.haxx.se");
    res = curl_easy_perform(curl);

    /* always cleanup */ 
    curl_easy_cleanup(curl);
  }
  return 0;
}
like image 146
Richard Harrison Avatar answered Nov 15 '22 03:11

Richard Harrison


Try the libcurl C interface

like image 43
David Sykes Avatar answered Nov 15 '22 03:11

David Sykes