C language calls the curl library to capture web images and curl to capture
The idea is to capture the webpage source code with curl and then search for the image URL with the keyword. # Include <stdio. h> # include <stdlib. h> # include <string. h> # include <curl/curl. h> void get_key_from_str (char * origin, char * str1, char * str2, char * key); int main (int argc, char ** argv) {CURL * curl; FILE * fp = NULL, * fp_read = NULL; int file_size = 0; char * tmp = NULL; int flag = 0; char key [1024] = {0 }; char str1 [128] = {0}; char str2 [128] = {0}; if (fp = fopen ("test.txt", "w") = NULL) {return 1 ;} Curl = curl_easy_init (); if (curl) {flag = 1; curl_easy_setopt (curl, CURLOPT_URL, argv [1]); // curl sets the URL curl_easy_setopt (curl, expires, fp); // Save the webpage source code to a file. It seems that only files can be saved, and the string curl_easy_perform (curl) cannot be saved; // start to capture curl_easy_cleanup (curl); fclose (fp ); fp_read = fopen ("test.txt", "rb"); fseek (fp_read, 0, SEEK_END); // move the pointer to the end of the text file_size = ftell (fp_read ); // calculate the text size fseek (fp_read, 0, SEEK_SET); // move the pointer To the front tmp = (char *) malloc (file_size * sizeof (char); // malloc a piece of memory printf ("file_size: % d \ n", file_size ); fread (tmp, file_size, sizeof (char), fp_read); // read the file fclose (fp_read); snprintf (str1, sizeof (str1 ), "img src = \" "); snprintf (str2, sizeof (str2)," \ ""); get_key_from_str (tmp, str1, str2, key ); // obtain the URL printf ("key: % s \ n", key); free (tmp);} if (! Flag) {fclose (fp);} return 0;} // capture the keyword void get_key_from_str (char * origin, char * str1, char * str2, char * key) {char * p = strstr (origin, str1); char * q = strstr (p + strlen (str1), str2 ); int len = q-p-strlen (str1); snprintf (key, len + 1, "% s", p + strlen (str1 )); key [len + 1] = '\ 0';} gcc-g-Wall main. c-o test-lcurl. /test url