Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <curl/curl.h>
  5.  
  6. static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
  7. {
  8.   size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
  9.   return written;
  10. }
  11.  
  12. int main(void)
  13. {
  14.  
  15.   CURL *curl;
  16.   CURLcode res;
  17.  
  18.  
  19.  
  20.  
  21.   char tekst[]="url";
  22.   char tekst2[]=".txt";
  23.   char wynik[20][100];
  24.   char nazwa[20][100];
  25.   int i;
  26.  
  27.  
  28. for (i=0;i<5;i++) {
  29.  
  30.  
  31.  
  32.     snprintf(wynik[i], 100, "%s%d", tekst ,i);
  33.  
  34.     snprintf(nazwa[i], 100, "%d%s", i ,tekst2);
  35.  
  36.  
  37.     static const char *pagefilename = nazwa[i];
  38.     FILE *pagefile;
  39.  
  40.     curl_global_init(CURL_GLOBAL_DEFAULT);
  41.  
  42.     curl = curl_easy_init();
  43.     if(curl) {
  44.  
  45.       curl_easy_setopt(curl, CURLOPT_URL, wynik[i]);
  46.       curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
  47.       curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
  48.       curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
  49.       curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookies.txt");
  50.       curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  51.       curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
  52.       curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
  53.  
  54.       pagefile = fopen(pagefilename, "wb");
  55.       if(pagefile) {
  56.         curl_easy_setopt(curl, CURLOPT_WRITEDATA, pagefile);
  57.         res = curl_easy_perform(curl);
  58.         if(res != CURLE_OK)
  59.                 fprintf(stderr, "curl_easy_perform() failed: %s\n",
  60.              curl_easy_strerror(res));
  61.         fclose(pagefile);
  62.       }
  63.  
  64.  
  65.  
  66.  
  67.       curl_easy_cleanup(curl);
  68.     }
  69.     curl_global_cleanup();    
  70.  
  71.   return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement