more advanced parsing
This commit is contained in:
27
net/net.cpp
27
net/net.cpp
@@ -7,29 +7,42 @@ Net::Net() {}
|
||||
|
||||
size_t writeCallback(void* contents, size_t size, size_t nmemb, void* userp) {
|
||||
size_t totalSize = size * nmemb;
|
||||
((std::string*)userp)->append(std::string((char*)contents));
|
||||
((std::string*)userp)->append(std::string((char *)contents));
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
size_t write_data(void *buffer, size_t size, size_t nmemb, void *filename) {
|
||||
FILE *f = fopen(((std::string *)filename)->c_str(), "w");
|
||||
size_t written = fwrite(buffer, size, nmemb, f);
|
||||
// size_t write_data_to_file(void *buffer, size_t size, size_t nmemb, void *filename) {
|
||||
// FILE *f = fopen(((std::string *)filename)->c_str(), "wb");
|
||||
// size_t written = fwrite(buffer, size, nmemb, f);
|
||||
|
||||
fclose(f);
|
||||
// fclose(f);
|
||||
|
||||
// return written;
|
||||
// }
|
||||
|
||||
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
|
||||
size_t written;
|
||||
written = fwrite(ptr, size, nmemb, stream);
|
||||
return written;
|
||||
}
|
||||
|
||||
// size_t write_data(void *buffer, size_t size, size_t nmemb, void *string_buffer) {
|
||||
// *(std::string *)string_buffer = std::string((char *)buffer);
|
||||
// std::cout << (char*)buffer << std::endl;
|
||||
// return size;
|
||||
// }
|
||||
|
||||
void Net::get_file(std::string url, std::string filename) {
|
||||
CURL *handle = curl_easy_init();
|
||||
|
||||
curl_easy_setopt(handle, CURLOPT_URL, url.c_str());
|
||||
FILE *f = fopen(filename.c_str(), "wb");
|
||||
|
||||
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_data);
|
||||
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &filename);
|
||||
curl_easy_setopt(handle, CURLOPT_WRITEDATA, f);
|
||||
|
||||
auto success = curl_easy_perform(handle);
|
||||
|
||||
fclose(f);
|
||||
curl_easy_cleanup(handle);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp);
|
||||
size_t write_data_to_file(void *buffer, size_t size, size_t nmemb, void *userp);
|
||||
size_t writeCallback(void* contents, size_t size, size_t nmemb, void* userp);
|
||||
|
||||
class Net
|
||||
@@ -14,6 +14,7 @@ public:
|
||||
void get_file(std::string url, std::string filename);
|
||||
std::string fetch_check_data_from_ofdru(std::string fn, std::string fd, std::string fi, std::string datetime, int operation, int total, std::string captcha);
|
||||
void get_captcha_from_ofdru();
|
||||
std::string get_data(std::string url);
|
||||
};
|
||||
|
||||
#endif // NET_H
|
||||
|
||||
Reference in New Issue
Block a user