Skip to content

Instantly share code, notes, and snippets.

@R3DHULK
Created February 4, 2023 16:52
Show Gist options
  • Save R3DHULK/b1a777016f56bb27d6153afb3b45d3f9 to your computer and use it in GitHub Desktop.
Save R3DHULK/b1a777016f56bb27d6153afb3b45d3f9 to your computer and use it in GitHub Desktop.
Web Scrapping In CPP
#include <iostream>
#include <curl/curl.h>
#include <string>
size_t write_data(char *ptr, size_t size, size_t nmemb, void *userdata) {
std::string html = (std::string)userdata;
html->append(ptr, size * nmemb);
return size * nmemb;
}
int main(void) {
CURL *curl;
CURLcode res;
std::string html;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &html);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
std::cout << html << std::endl;
return 0;
}
@R3DHULK
Copy link
Author

R3DHULK commented Feb 4, 2023

help me
web-scrapper.cpp:2:10: fatal error: curl/curl.h: No such file or directory
2 | #include <curl/curl.h>
| ^~~~~~~~~~~~~
compilation terminated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment